Im tryin to connect two rp2040s thrugh rx and tx. Im using IDE 2.0.4 and im attempting to light up an LED on and off just to check for a connection.
my transmitter code is:
//#define PIN_SERIAL_TX (0ul)
//#define PIN_SERIAL_RX (1ul)
//...
//#define SERIAL_HOWMANY 1
int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
int i = 0;
void setup() {
// initialize serial communication: //Serial.begin(9600);
Serial1.begin(9600); //Serial.setTimeout(50);
delay(100);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
}
void loop() {
// see if there's incoming serial data:
while(Serial1.available()){
delay(2);
incomingByte = Serial1.readString();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 2) {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 1) {
digitalWrite(ledPin, LOW);
}
I guess you have tried everything possible, just solve the RxD and TxD problem for my self and one thing I can tell you is, unplug and plugin the board again, expecially if you are "crussing" around different apps, etc.
In general, make sure that the connections are right, that means, e.g. when reading the serial via the rxd, txd on tiny, then the ftdi connection is the same (rxd->rxd, etc.). If you are using the "external" not arduino serial port reader app then make sure your bauds, etc. are properly set, in most cases, the other settings are ok! In addition, if you are using the ftdi, etc. make sure that your driver is ok...
and do not bother with code too much, it should works straight via the Serial.begin(); and Serial.println() within the main loop, for example.
int ledPin = 13; // the pin that the LED is attached to
char incomingByte; // a variable to read incoming serial data into
int i = 0;
void setup() {
// initialize serial communication:
//Serial.begin(9600);
Serial1.begin(9600);
//Serial.setTimeout(50);
delay(100);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
}
void loop() {
// see if there's incoming serial data:
while(Serial1.available()){
delay(2);
incomingByte = Serial1.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == '2') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == '1') {
digitalWrite(ledPin, LOW);
}
}
}
You should add serial debug output to the serial monitor
THis will make visible what your code is doing (or not doing)
and this will guide you to the bug
int ledPin = 13; // the pin that the LED is attached to
char incomingByte; // a variable to read incoming serial data into
int i = 0;
void setup() {
// initialize serial communication:
//Serial.begin(9600);
Serial.begin(115200);
Serial.println("Setup-Start");
Serial1.begin(9600);
//Serial.setTimeout(50);
delay(100);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
}
void loop() {
// see if there's incoming serial data:
while(Serial1.available()){
delay(2);
incomingByte = Serial1.read();
Serial.print("incomingByte=");
Serial.println(incomingByte);
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == '2') {
Serial.print("received a 2");
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == '1') {
Serial.print("received a 1");
digitalWrite(ledPin, LOW);
}
}
}
I get the message "17:01:07.735 -> incomingByte=" and a little empty square next to the =. The transmitter is writing 0 and 1 and I see the Serial.print("incomingByte="); which i gess means that Serial 1 is available?
How can I check for that other than watching the serial monitor? it seems to write Serial1.print("1"); Serial.println("Serial1 send 1") perfectly and Ive checked wiring, Im completely lost
posting the exact sender and the exact receiver-code
posting what you get in the serial monitor as a code-section too
so that others can analyse what you received in the serial monitor
using looping back from
serial Tx to serial1 Rx
serial Rx to serial1 Tx
of one and the same microcontroller
with using the same baudrate on both serial interfaces
using the command serial.write() to send really a single byte instead
of a string
printing the value of the received byte as
binary
decimal
using a
USB-to-COM-Port-adapter and receiving the sended bytes with a terminal software and printing the received bytes as decimal or hexadecimal values
connecting 8 LEDs to the receivers IO-pins and switch on / off the 8 IO-pins according to the bits of the received byte
moth later. Sorry for not writting back, had many exams to deal with(im in uni). Bought a new RP2040, copied your code and its all working!!! Thousand thanks