0% found this document useful (0 votes)
169 views

Arduino Obd2

The document contains code to initialize an OBD-II device and read data from it. It sets up serial communication on two ports, resets and configures the device, then enters a loop to continuously read and print response data from the device. It uses buffers to store response data, checks for newline characters, and clears the buffers between reads.

Uploaded by

Silmar Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

Arduino Obd2

The document contains code to initialize an OBD-II device and read data from it. It sets up serial communication on two ports, resets and configures the device, then enters a loop to continuously read and print response data from the device. It uses buffers to store response data, checks for newline characters, and clears the buffers between reads.

Uploaded by

Silmar Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

char rxData[20];
2. char rxIndex = 0;
3. String inputString = "";
4. boolean stringComplete = false;
5. void setup(){
6. Serial.begin(9600);
7. Serial1.begin(9600);
8. Serial.flush();
9. Serial1.flush();
10. //Reset IC
11. Serial1.println("ATZ");
12. delay(1500);
13. getOBDResponse();
14. Serial.println(rxData);
15. clearBuffer();
16. getOBDResponse();
17. Serial.println(rxData);
18. clearBuffer();
19. //Sets IC to defults
20. Serial1.println("ATD");
21. delay(1000);
22. getOBDResponse();
23. Serial.println(rxData);
24. clearBuffer();
25. getOBDResponse();
26. Serial.println(rxData);
27. clearBuffer();
28. Serial1.println("ATSP0");
29. delay(1000);
30. getOBDResponse();
31. Serial.println(rxData);
32. clearBuffer();
33. getOBDResponse();
34. Serial.println(rxData);
35. clearBuffer();
36. Serial1.println("010D");
37. delay(1000);
38. getOBDResponse();
39. Serial.println(rxData);
40. clearBuffer();
41. getOBDResponse();
42. Serial.println(rxData);
43. clearBuffer();
44. Serial1.println("ATDP");
45. delay(1000);
46. getOBDResponse();
47. Serial.println(rxData);
48. clearBuffer();
49. getOBDResponse();
50. Serial.println(rxData);
51. clearBuffer();
52. //Bus initiation
53. Serial1.println("ATSI");
54. delay(3000);
55. getOBDResponse();
56. Serial.println(rxData);
57. clearBuffer();
58. getOBDResponse();
59. Serial.println(rxData);
60. clearBuffer();
61. Serial.flush();
62. Serial1.flush();
63. }
64. void loop(){
65. /*
66. if(stringComplete){
67. Serial.println(inputString);
68. inputString = "";
69. stringComplete = false;
70. }
71. */
72. Serial1.flush();
73. Serial1.println("010D");
74. getOBDResponse();
75. Serial.println(rxData);
76. clearBuffer();
77. getOBDResponse();
78. Serial.println(rxData);
79. clearBuffer();
80. }
81. void getOBDResponse(){
82. char inChar = 0;
83. while(inChar != '\r'){
84. if(Serial1.available() > 0){
85. if(Serial1.peek() == '\r'){
86. inChar = Serial1.read();
87. rxData[rxIndex] = '\0';
88. rxIndex = 0;
89. }else{
90. inChar = Serial1.read();
91. rxData[rxIndex++] = inChar;
92. }
93. }
94. }
95. }
96. void clearBuffer(){
97. int i;
98. for(i = 0; i < 20; i++){
99. rxData = '';
100. }
101. }
102. void serialEvent1(){
103. while(Serial1.available()){
104. char input = (char)Serial1.read();
105. inputString += input;
106. if(input == '\r'){
107. stringComplete = true;
108. }
109. }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy