I'm trying to communicate my PC with an Arduino Mega via serial and after send the message via NRF to another Arduino.
But I don't know if the message is send correctly or if it even send the message. Because I can't debug using Serial Monitor. If it is opened the serial port appear as busy.
When I execute the code the TX led on the Arduino blinks, but nothing is send via NRF.
I made some tests using only the NRF between the Arduinos and it's working, but when I try using the PC - Arduino serial communication, nothing happens.
C Code
#include <stdio.h>
#include <string.h>
char arduinoPort[] = "/dev/ttyACM0";
int main() {
char buffer[] = {'1'};
int error = 10;
FILE *usb_port;
usb_port = fopen(arduinoPort, "rwb");
if(!usb_port) {
perror(arduinoPort);
return 1;
}
//memcpy(buffer, &error, sizeof(error));
fwrite(buffer, sizeof(char), sizeof(buffer), usb_port);
fclose(usb_port);
return 0;
}
Arduino Code
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include <RF24_config.h>
RF24 radio(7, 8); // CE, CSN
uint64_t address = 0xF0F0F0F0E1LL;
void setup() {
Serial.begin(9600);
printf_begin();
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
radio.printDetails();
}
void loop() {
if(Serial.available() > 0) {
char byteLido = Serial.read();
radio.write(&byteLido, sizeof(byteLido));
delay(1000);
}
}
stty/dev/ttyACM0 to the correct baud rate?Ccode