Arduino terminal console

Hello, i am creating a terminal console for arduino(soon on GitHub), and i have found a timing problem, thus the SPI write time takes too long, so i got a serial buffer overFlow on decent speeds. At 1200 bauds works perfect.

(1)One possible solution is to take care of SPI writing AND Serial reading at the same time, usign the 2 cores.

(1) Using multicore_fifo_push**** and multicore_fifo_pop**** i can pass a 32 bit value to the other thread, but i need to pass a whole(80x24+colors) array of uint8_t to be printed on display... so?

(2)Another possible solution is a big increase of Serial buffer size.

(2) At "RingBuffer.h" there is "#define SERIAL_BUFFER_SIZE 64", which i can modify, but doesn't seem to be a viable way, because the library woudn't work on other systems where the value is not modified.

Testing hardware 2: Rpi Pico+ST7735 display+m5Stack keyboard

Any help would be appreciated.

Thanks in advance.

edited to embed the picture. Don't post links to outside the forum, very few people would follow them.

to get help you need to provide way more information. Please read How to get the best out of this forum and add to your post accordingly

post the code (in highlighted area after clicking </> icon)

Hi, if the .run() at the loop() is commented, and the multicore enabled, so the tmp function is used to run the TTYS0_Display.run(); via multicore_launch_core1, a mbed_fault_handler is rised, to core_util_critical_section_enter on core 0, core 1 it's halted at multicore_fifo_pop_blocking_inline.

Thanks.

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <menuOptionsA.h>
#include <Adafruit_SH1106_kbv.h>
#include <Adafruit_ST7735.h>
//#include <TtyAdafruitSH1106.h>
#include <TtyAdafruitST7735.h>
#include <keyboards.h>
#include <pico/multicore.h> //https://raspberrypi.github.io/pico-sdk-doxygen/group__pico__multicore.html

//Adafruit_ST7735 tft = Adafruit_ST7735(6, 7, 8); //Atmega329P 
//Adafruit_ST7735 display = Adafruit_ST7735(&SPI,p14, p15, p13);// pi pico
//Adafruit_SH1106_kbv display(128, 64,&SPI,p15,p13,p14);// for Raspberry pi pico 
//TtyAdafruitSH1106 TTYS0_Display = TtyAdafruitSH1106(&display);// as parameter bc if else init() needed.
Adafruit_ST7735 displaycharTmp = Adafruit_ST7735(&SPI,p14, p15, p13);// font amplada=6 alçada=8, amplada text = 26, alçada=16?, rotacio=1
TtyAdafruitST7735 TTYS0_Display = TtyAdafruitST7735(&displaycharTmp);// as parameter bc if else init() needed.

IICTtyKeyboard TTYS0_Keyboard = IICTtyKeyboard();// keyboard is not as an argument bc at construction, Wire.begin() fails

UART Serial2(p0, p1);

void tmp(){
  TTYS0_Display.run();// after spi+wire init done
}
void setup() {
  Wire.begin();
  SPI.begin();
  Serial2.begin(9600);
  Serial.begin(57600);
  
  TTYS0_Display.keyboard = &TTYS0_Keyboard;
 
  TTYS0_Display.init();// after spi+wire init done
  
  pinMode(p6, OUTPUT);// overflow led hardware test
  digitalWrite(p6, HIGH);
  delay(1000);
  digitalWrite(p6, LOW);
}
uint8_t charTmp;

void loop(void) {

    //multicore_launch_core1(tmp) ;
    TTYS0_Display.run();

    if(TTYS0_Display.available()){
        charTmp = TTYS0_Display.read();
        Serial2.write(charTmp);
        Serial2.flush();
    }
    if(Serial2.available()){
      if(Serial2.available() == SERIAL_BUFFER_SIZE)digitalWrite(p6, HIGH);
        charTmp = Serial2.read();
        //Serial.write(charTmp);
        TTYS0_Display.write(charTmp);
    }
}

Solved by using mbed os threads:

mbed::Callback<void()> tmp(){
  while(true){
    //std::ThisThread::sleep_for(1000);
    TTYS0_Display.run();// refresh display via SPI if needed
  }
}
rtos::Thread thread;
 thread.start(tmp);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.