Second firmware live stream happening this weekend: viewtopic.php?f=13&t=3992
Help with building your Speeduino, installing it, getting it to run etc.
By gbilski
#43062
I have a problem with the sketch that I have for reading data from serial 3. I am using the sketch to display onto a small LCD. If I just start Speedy with the Arduino nano attached to the serial port, then I just get random not changing values for the display. If I then just unplug the serial port and back again, then the data displays correctly. I am wondering if there is something wrong with the way I am initialising the sketch. Would anyone be able to check and see what I have done wrong? Thanks, Gary

#include <SoftwareSerial.h>
#include <gfxfont.h>
#include <Adafruit_ST7735.h> //LCD display library
#include <Fonts/FreeSans24pt7b.h> //Fonts
#include <SPI.h> //for the SPI connection
SoftwareSerial Serial3(2, 3); // RX, TX
// For the ST7735 LCD 1.44" 128x128 screen
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8

// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,TFT_DC,TFT_RST);

static uint32_t oldtime=millis(); // for the timeout
byte SpeedyResponse[39]; //The data buffer for the serial data
byte ByteNumber; // pointer to which byte number we are reading currently
byte ResponseLength; // how long response is asked from speeduino
unsigned int AFR_RAW; //AFR value
float o2val; //AFR value
int MAP; //MAP from speeduino
int BARO; //barometer from speeduino
float boost1;
float boost;
volatile float peakboost = 0; // Set peak memory to 0. We don't save this to flash so resets on start up

void setup(){
Serial.begin(115200); // baudrate for Speeduino is 115200
Serial3.begin(38400); // for debugging

//set SPI spped
SPI.setClockDivider(SPI_CLOCK_DIV16);

// The 1.44" TFT LCD
// Use this initializer (uncomment) if you're using a 1.44" TFT
tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK);
tft.setTextSize(4);

// zero the data so it's not just random garbage
boost = 0;
boost1 = 0;
o2val = 0;
MAP = 0;
BARO = 0;
ResponseLength = 37;

requestData(); // all set. Start requesting data from speeduino
}

//Send r to request data from Speeduio
void requestData() {
Serial.write("r"); //new type real time data.
Serial.write(0x00); //Speeduino TS canID, not used atm.
Serial.write(0x30); //command type, 0x30 for real time data.
Serial.write(4); //offset for the data. LSB
Serial.write(0x00); // offset is in 2 bytes. LSB first.
Serial.write(ResponseLength); //how many bytes we need back. LSB
Serial.write(0x00); // number of bytes is in 2 bytes. LSB first.
}

//display the needed values in serial monitor for debugging
void displayData(){
Serial3.print (MAP); Serial3.print("\t");
Serial3.print (BARO); Serial3.print ("\t");
Serial3.print ("BOOST: "); Serial3.print (boost); Serial3.print("\t");
Serial3.print ("AFR: "); Serial3.print (o2val); Serial3.println("\t");
}

void processData(){ // To process data for display
if(SpeedyResponse[1] == 0x30){ //only process if serial response array has the right start point.
MAP = SpeedyResponse[2]; // MAP low byte as never going above 255
BARO = SpeedyResponse[38];
boost = float(MAP - BARO)/100;
AFR_RAW = SpeedyResponse[8];
o2val = float(AFR_RAW)/10;
}
if (boost > peakboost){ // If current boost is higher than peak, store in peak memory
peakboost = boost; }// Store current boost in peak memory
}

void displayScreen() {
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setTextSize(4);
tft.setCursor(5,30);
if (o2val > 15.5) {
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
tft.print(o2val);
}
else if (o2val < 12) {
tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
tft.print(o2val);
}
else {
tft.print(o2val);
}

//this will print the boost value in Bar. Also allows for the - sign so that the display doesn't jump right when present.
// tft.fillRect(0, 119, 127, 24, ST7735_BLACK);
if (boost >= 0 && boost <= 1) {
tft.fillRect(4, 107, 20, 4, ST7735_BLACK);
tft.setCursor(28, 95);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.print(boost);
}
//change text to yellow if boost > 1
else if (boost > 1) {
tft.fillRect(4, 107, 20, 4, ST7735_BLACK);
tft.setCursor(28, 95);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
tft.print(boost);
}
// different start position to accomodate the - symbol and make the text green
else {
tft.setCursor(4, 95);
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.print(boost);
}
//print AFR, BOOST, peak boost
tft.setTextSize(2);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor( 9,5);
tft.print("AFR");
tft.setCursor(9,70);
tft.print("BOOST");
tft.setCursor(75,70);
tft.print(peakboost);
}

void loop() {
if (Serial.available () > 0) { // read bytes from serial
SpeedyResponse[ByteNumber ++] = Serial.read();
}
if (ByteNumber > (ResponseLength +1)){ // After the data from speeduino has been received so time to process it
oldtime = millis(); // All ok. zero out timeout calculation
ByteNumber = 0; // zero out the byte number pointer
processData(); // do the necessary processing for received data
// displayData(); // only required for debugging
displayScreen(); // display values on screen
requestData(); //restart data reading
}
if ( (millis()-oldtime) > 500) { // timeout if for some reason reading serial3 fails
oldtime = millis();
ByteNumber = 0; // zero out the byte number pointer
requestData(); //restart data reading
}
}

Just be careful with the firing order.... as the […]

I fixed the timing problem, it has no jitter now. […]

New 202005 firmware

is it possible there's something particular in you[…]

Yes although a simple trigger for fuel only will s[…]

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