For any discussion not specifically related to your project
By GMC270
#17207
Hi guys,

Im trying to get realtime data from speeduino to the serial monitor via "R" command but it returns strange values (mostly 255). Does anybody know what I am doing wrong?

Following code is programmed on an Arduino which has TX1/Rx1 connected to Speeduino's RX0/TX0.
Code:

void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}

void loop() {
int index = 0;
byte data[40];
Serial1.write("R");
if (Serial1.available())
{
while(index<39)
{
data[index] = Serial1.read();
Serial.println(data[index]);
index++;
}
Serial.println("------");
Serial.flush();
}
delay(1000);
}

Data I receive on serial monitor:
------
82
255
255
255
255
255
255
255
82
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
------
By dazq
#17211
If you intend to keep your device permanently attached to speeduino , even whilst tuning , better to use serial3 on the speeduino...
Enable it by selecting the can enable option.
Send an "A" though not "R"
See the cancomms.ino for the reply protocol.
#17228
Thanks a lot,
I enabled CAN communication in Tunerstudio, I connected Speeduinos RX/TX3 to RX/TX1 of the arduino. Changed baudrate, changed the packet size to 37 ( in code: byte data[37])
I see more reasonable values but the values change place all the time and still some random 255s appear.

Does anyone know how to improve this?

Arduino runs following code:

void setup() {
Serial.begin(9600);
Serial1.begin(115200);
}

void loop() {
byte data[37];
Serial1.write("A");
if (Serial1.available())
{
data[index] = Serial1.read();

for(int index = 0; index <37; index++)
{
data[index] = Serial1.read();
Serial.print(index);
Serial.print("\t");
Serial.println(data[index]);
}
Serial.println("------");
Serial.println(sizeof(data));
Serial.println("------");
Serial.flush();
}
delay(1000);
}


Serial monitor output (index nr, value):
1 93
2 170
3 228
4 190
5 242
6 233
7 151
8 215
9 108
10 121
11 108
12 170
13 169
14 150
15 97
16 208
17 199
18 5
19 157
20 41
21 245
22 106
23 25
24 101
25 0
26 0
27 0
28 0
29 0
30 100
31 0
32 3
33 81
34 37
35 214
36 168
------
37
------
0 188
1 242
2 233
3 221
4 217
5 253
6 100
7 121
8 100
9 0
10 0
11 100
12 98
13 152
14 0
15 142
16 0
17 0
18 9
19 45
20 105
21 47
22 77
23 6
24 101
25 0
26 0
27 0
28 0
29 0
30 100
31 0
32 0
33 209
34 249
35 244
36 221
------
37
------
0 82
1 189
2 215
3 255
4 116
5 121
6 236
7 253
8 63
9 75
10 11
11 6
12 119
13 163
14 145
15 163
16 27
17 251
18 169
19 202
20 11
21 13
22 173
23 87
24 1
25 183
26 181
27 253
28 65
29 37
30 174
31 64
32 5
33 30
34 49
35 10
36 122
------
37
------
0 118
1 255
2 100
3 121
4 100
5 0
6 0
7 100
8 98
9 152
10 0
11 142
12 0
13 0
14 9
15 45
16 103
17 47
18 77
19 6
20 101
21 0
22 0
23 0
24 0
25 0
26 100
27 0
28 2
29 65
30 37
31 176
32 64
33 5
34 30
35 49
36 10
------
37
------
0 119
1 118
2 255
3 100
4 121
5 100
6 0
7 0
8 100
9 98
10 152
11 0
12 142
13 0
14 0
15 9
16 45
17 112
18 47
19 77
20 6
21 101
22 0
23 0
24 0
25 0
26 0
27 100
28 0
29 0
30 83
31 120
32 111
33 101
34 108
35 127
36 121
------
37
------
By dazq
#17231
Your not decoding the stream correctly.
Send the "A"
You get and "A" reply first,
Then the number of bytes it will be sending (so currently 37)
Then it sends the data bytes.
#17248
// Speeduino's RX3/TX3.



#include <SoftwareSerial.h>

volatile boolean hasSync;
unsigned int RPM;
long longRPM;
int mapADC;
long MAP; //Has to be a long for PID calcs (Boost control)
int baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running
byte TPS; //The current TPS reading (0% - 100%)
byte TPSlast; //The previous TPS reading
unsigned long TPS_time; //The time the TPS sample was taken
unsigned long TPSlast_time; //The time the previous TPS sample was taken
byte tpsADC; //0-255 byte representation of the TPS
byte tpsDOT;
int rpmDOT;
byte VE;
byte O2;
byte O2_2;
int coolant;
int cltADC;
int i;
int IAT;
int iatADC;
int batADC;
int O2ADC;
int O2_2ADC;
int dwell;
byte dwellCorrection; //The amount of correction being applied to the dwell time.
byte battery10; //The current BRV in volts (multiplied by 10. Eg 12.5V = 125)
byte advance;
byte corrections;
byte TAEamount; //The amount of accleration enrichment currently being applied
byte egoCorrection; //The amount of closed loop AFR enrichment currently being applied
byte wueCorrection; //The amount of warmup enrichment currently being applied
byte batCorrection; //The amount of battery voltage enrichment currently being applied
byte iatCorrection; //The amount of inlet air temperature adjustment currently being applied
byte launchCorrection; //The amount of correction being applied if launch control is active
byte afrTarget;
byte idleDuty;
byte flex; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85.
unsigned long TAEEndTime; //The target end time used whenever TAE is turned on
volatile byte squirt;
volatile byte spark;
byte engine;
unsigned int PW; //In uS
volatile byte runSecs; //Counter of seconds since cranking commenced (overflows at 255 obviously)
volatile byte secl; //Continous
volatile int loopsPerSecond;
boolean launchingSoft; //True when in launch control soft limit mode
boolean launchingHard; //True when in launch control hard limit mode
int freeRAM;
byte response[64];


SoftwareSerial mySerial(10, 11); // RX, TX



void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
mySerial.begin(115200);


}

void loop() { // run over and over


mySerial.write("A");

while (mySerial.available() > 0)

{
for (i = 0; i <64; i++)
{response = mySerial.read();}

}






secl = response[2]; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
squirt = response[3]; //Squirt Bitfield
engine = response[4]; //Engine Status Bitfield
dwell = response[5]; //Dwell in ms * 10
MAP = response[6] ; //map value is divided by 2
IAT= response[7] ; //mat
coolant = response[8]; //Coolant ADC
tpsADC = response[9]; //TPS (Raw 0-255)
battery10 = response[10]; //battery voltage
O2 = response[11]; //O2
egoCorrection = response[12]; //Exhaust gas correction (%)
iatCorrection = response[13]; //Air temperature Correction (%)
wueCorrection = response[14]; //Warmup enrichment (%)
RPM = ((response [16] << 8) | (response [15])); //Junto todo en una variable
TAEamount = response[17]; //acceleration enrichment (%)
// 0x00 = response[18]; //Barometer correction (%)
corrections = response[19]; //Total GammaE (%)
VE = response[20]; //Current VE 1 (%)
afrTarget = response[21];
PW = response[22]; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
tpsDOT = response[23]; //TPS DOT
advance = response[24];
TPS = response[25]; // TPS (0% to 100%)
loopsPerSecond = ((response [27] << 8) | (response [26])); //Junto todo en una variable
freeRAM = ((response [29] << 8) | (response [28])); //Junto todo en una variable

batCorrection = response[30]; //Battery voltage correction (%)
spark = response[31]; //Spark related bitfield
O2_2 = response[32]; //O2

rpmDOT = ((response [34] << 8) | (response [33])); //Junto todo en una variable

flex = response[35]; //Flex sensor value (or 0 if not used)

I rewired a few grounds and tested the TPS and rel[…]

Thanks, car runs great now !!! Going to drift even[…]

sauver moteur v8

bonsoir je m appel jean marie et j habite en Franc[…]

Ignition Angle doubled?

I just erased the flash, went back to 2023-10, cre[…]

Still can't find what you're looking for?