Serial.read() question

Hi,

I have written a perfectly working code for my Uno and want to run it on my Pro Mini 3.3V 1Mhz, here is my code for the Uno:

#define ENABLE_GxEPD2_GFX 0

#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>

#if defined(__AVR)
#define MAX_DISPAY_BUFFER_SIZE 800 //
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=*/ 6, /*DC=*/5, /*RST=*/4, /*BUSY=*/7)); // GDE0213B1, phased out
#endif

#include "GxEPD2_boards_added.h"
#include <AltSoftSerial.h>

AltSoftSerial  altSerial; // RX, TX


char bytes[160];

void setup()
{
  display.init(115200);
  Serial.begin(115200);

  receive();
  display.drawImage(bytes, 0, 0, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 10, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 20, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 30, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 40, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 50, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 60, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 70, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 80, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 90, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 100, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 110, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 120, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 130, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 140, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 150, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 160, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 170, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 180, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 190, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 200, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 210, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 220, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 230, 128, 10, false, true, false);
  receive();
  display.drawImage(bytes, 0, 240, 128, 10, false, true, false);
 
  display.powerOff();
}

void loop()
{
}

void receive()
{
  int i = 0;
  while (i < 160)
  {
    if (Serial.available())
    {
      bytes[i] = Serial.read();
      Serial.write(bytes[i]);
      i++;
    }
  }
}

I changed the baud rate from 115200 to 9600, because my Pro Mini runs with 1Mhz and removed the AltSoftSerial and I’m now using the Hardware Serial (TX,RX / D0,D1).

My Pro Mini is always reading -1, which is 0xFF. I tried Serial.available() and Serial.available()>0 and Serial.available()>=2, but it still reads -1. My Uno never reads the -1 and waits for a input.

Anybody have a idea?

Did you change the baudrate on the other end of the serial bus as well?

Did you connect the hardware lines correctly?

Maybe this can help. Especially the section about serialEvent()

I solved this one myself, just added a 1k ceramic resistor to tx :smiley: Thanks for all your help.

Moneyhunter:
I solved this one myself, just added a 1k ceramic resistor to tx :smiley: Thanks for all your help.

To what did you connect the other end of the resistor?

...R

Sry, my fault (I don't know why I wrote that). It's of course a 0.1uF ceramic capacitor. I passed that signal through the cap and it worked.