Pages: 1 2 [3]   Go Down
Author Topic: What is the Arduino Uno Serial buffer size?  (Read 18683 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It wouldn't do me much good to calculate the data on the fly if the checksum doesn't match though, right? That would mean one or all of the data is faulty and everything I just calculated would need to be disregarded.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put the code that sends the request into a a function and it seems to send the initial request from the setup, then it reads it on the first iteration, and then sends the next request, but it does not read the second stream of data. I think this has something to do with the mySerial.available() function. Hopefully you guys might be able to spot the problem with my code:

Code:
/* 
 This program is used for an Arduino to request and retrieve
 data from an 07 Buell XB9SX Lightning ECM DDFI-2,
 EEPROM Version: BUEIB
 
 Currently the Arduino successfully sends a request code and
 receives all 107 bytes of Real-time data, and displays
 on the TPS on the LCD screen and all data via serial monitor.
 The program is supposed to be running in real time, but only
 shows the very first iteration. The problem may have something
 to do with the mySerial.avalable() function.
 
 Created by Michael Blaylock
 */

// include the library code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

//new serial pins for ECM, 0 and 1 caused interferance from PC
#define rxPin 2
#define txPin 3

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte inArray[9]; //request code for real-time data
byte outArray[107]; //real-time data series from ECM
byte long Value;
int IterationNumber = 0;
int ByteNumber;

void setup(){
  lcd.begin(16, 2);  // set up the LCD's number of columns and rows:
  mySerial.begin(9600);  // baud rate for the ECM is 9600
  Serial.begin(9600);
  ByteNumber = 0;
  inArray[0]=0x01; //SOH
  inArray[1]=0x00; //Emittend
  inArray[2]=0x42; //Recipient
  inArray[3]=0x02; //Data Size
  inArray[4]=0xFF; //EOH
  inArray[5]=0x02; //SOT
  inArray[6]=0x43; //Data 1 //0x56 = Get version, 0x43 = Get runttime data
  inArray[7]=0x03; //EOT
  inArray[8]=0xFD; //Checksum

  lcd.setCursor(0,0);
  //Stream request data series to ECM as HEX
  for (int i = 0; i<9; i+=1){
    mySerial.write(inArray[i]);
    lcd.print(inArray[i],HEX); //print sent HEX code
  }
  //mySerial.write(0x01 0x00 0x43 0x02 0xFF 0x02 0x43 0x03 0xFD);
}

//Send data request to ECM
void requestData() {
  for (int i = 0; i<9; i+=1){
    mySerial.write(inArray[i]);
    //lcd.setCursor(0,0);
    //lcd.print("printing"+i);
  }
  Serial.print("Data Request Sent");
  delay(100);
}

//display the array in serial monitor one time
void displayData(){
  //if(IterationNumber < 3){
    for (int j = 0; j<107; j+=1){
      Serial.println(outArray[j],HEX);
    }
    //IterationNumber ++;
    Serial.println("Data Printed");
  //}
}

//Display the Throttle Position Sensor
void TPS(){
  unsigned Value = outArray[91] << 8 | outArray[90];
  lcd.setCursor(0,1);
  lcd.print("TPS: ");
  lcd.print(Value);
}

void loop() {
  // fill buffer
  if (mySerial.available () > 0)
    outArray[ByteNumber ++] = mySerial.read();
  if (ByteNumber > 106){// process it
    Serial.println("Data Stream Read");
    ByteNumber = 0;  // ready for next time
    displayData();
    lcd.setCursor(1,1);
    TPS();
    requestData();
  }  // end if full
}  // end of loop

This is the response I get:

Code:
Data Stream Read
1
42
0
64
FF
2
6
7B
5A
0
0
0
0
0
0
0
0
BB
20
BB
20
38
36
38
36
33
0
F
4F
4
65
2
98
2
0
0
EE
2
1F
6
E8
3
0
0
E8
3
E8
3
E8
3
E8
3
30
4
30
4
0
80
0
0
0
0
0
0
0
FC
0
0
0
0
0
0
0
0
0
0
10
0
0
FF
FF
FF
FE
0
0
5
0
0
0
0
A1
0
1A
1
F0
BC
0
0
0
0
0
0
0
0
0
3
F5
Data Printed
Data Request Sent

My desire is for it to repeat this response over and over with newer run-time data, but like I mentioned, it isn't doing this like I thought it would.

I have not added any data verification yet with the header or checksum. So far the data coming in has been good and very consistent without skipping a beat, so I am going to focus on core functionality before I add in that feature.

EDIT: I just thought of something, would clearing the mySerial buffer before requesting more data help?
« Last Edit: March 31, 2012, 08:20:04 pm by Blaylock1988 » Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3734
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it still work (once) if you call requestData from setup rather than replicating the send loop there?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, you can see by the data it works the first time. I call the same bit of code from the function for a second and it seems to send the request but no data appears to be read and I don't know why.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3734
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I mean does it work if you call the function rather than replicating what it does, because they are not quite the same - the LCD print in setup introduces a (small) delay. I was wondering whether that difference is important.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GOOD NEWS!!!!

I got it working! It displays the information on my LCD screen quickly and in real-time. I will post a video of it in a few hours. The problem I was having was the location of the display() function. It was interfering with the data coming in and non of it would get read. I just removed it because I won't need since the arduino will be a stand alone on the bike with no serial monitor connected.

Thank you so much to everyone for the help, there is still a lot left I have to do. The main part of my project can start moving forward now with calculating torque, horsepower, and creating a shift indicator. I am excited!

Thanks again, and video coming soon!

Code:
/*  
 This program is used for an Arduino to request and retrieve
 data from an 07 Buell XB9SX Lightning ECM DDFI-2,
 EEPROM Version: BUEIB
 
 Currently the Arduino successfully sends a request code and
 receives all 107 bytes of Real-time data, and displays
 on the TPS on the LCD screen and all data via serial monitor.
 
 Created by Michael Blaylock
 */

// include the library code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

//new serial pins for ECM, 0 and 1 caused interferance from PC
#define rxPin 2
#define txPin 3

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte inArray[9]; //request code for real-time data
byte outArray[107]; //real-time data series from ECM
byte long TPS;
byte long ETemp;
int IterationNumber = 0;
int ByteNumber;
int Processing = 0;

void setup(){
  lcd.begin(16, 2);  // set up the LCD's number of columns and rows:
  mySerial.begin(9600);  // baud rate for the ECM is 9600
  Serial.begin(9600);
  ByteNumber = 0;
  inArray[0]=0x01; //SOH
  inArray[1]=0x00; //Emittend
  inArray[2]=0x42; //Recipient
  inArray[3]=0x02; //Data Size
  inArray[4]=0xFF; //EOH
  inArray[5]=0x02; //SOT
  inArray[6]=0x43; //Data 1 //0x56 = Get version, 0x43 = Get runttime data
  inArray[7]=0x03; //EOT
  inArray[8]=0xFD; //Checksum

  //mySerial.write(0x01 0x00 0x43 0x02 0xFF 0x02 0x43 0x03 0xFD);
  requestData();
}

//Send data request to ECM
void requestData() {
  //lcd.setCursor(0,0);
  for (int i = 0; i<9; i+=1)
    mySerial.write(inArray[i]);
  //Do not place code here
}

//display the array in serial monitor
void displayData(){
  for (int j = 0; j<107; j+=1){
    Serial.println(outArray[j],HEX);
  }
  Serial.println("Data Printed");
  Processing = 0;
}

//Display the Throttle Position Sensor
void callTPS(){
  unsigned TPS = outArray[91] << 8 | outArray[90];
  lcd.setCursor(0,0); //right then down
  lcd.print("TPS: ");
  lcd.print(TPS);
}

void callETemp(){
  unsigned ETemp = (outArray[31] << 8 | outArray[30]) * 0.18 -40;
  lcd.setCursor(0,1); //right then down
  lcd.print("ETemp: ");
  lcd.print(ETemp);
  lcd.print("degF");
}

void loop() {
  if (mySerial.available () > 0) {
    outArray[ByteNumber ++] = mySerial.read();
  }
  if (ByteNumber > 106){// process it
    Serial.println("Data Stream Read");
    //Processing = 0;
    ByteNumber = 0;  // ready for next time
    //displayData();
    lcd.setCursor(1,1);
    callTPS();
    callETemp();
    requestData();  //restart data
    //Do not place code here
  }  // end if full
}  // end of loop

« Last Edit: April 01, 2012, 06:32:38 pm by Blaylock1988 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GOOD NEWS!!!!
I got it working!

Hi Michael,

Thanks to your program I managed to receive serial PELCO commands. These commands are used to control
CCTV camera systems.  smiley

http://forum.arduino.cc/index.php?PHPSESSID=bhv3n6da4s1f2a8d0b3ip2er66&topic=155693.0
Logged

Pages: 1 2 [3]   Go Up
Jump to: