Hi there. I’m new to to the world of Arduino so apologies
I’m trying to create a system whereby a Digipot is controlled on an Arduino Duo using bit values generated from the analog pins of an Arduino Mega, using serial over RS232 (the final product will be over RS232 Fiber converters) . I’ve succeeded in controlling the digipot using analogread on the Duo - i.e with just one board, but when I try to send values from the analog pins on the mega to the serial port of the duo, instead of 0-1023, I get a range of ~48-56.
I’ve connected the two boards together using serial port 2 of the mega and a softserial port on the duo, wired TX to RX and with the grounds of the two boards connected. I’m then monitoring the values recieved using the normal serial port on the duo over usb on the serial monitor.
Here’s my code for testing the values recieved (ignoring the Digipot for now, as that seems to work OK in isolation…)
Mega Code:
void setup() {
Serial.begin(9600); // open USB serial port
Serial2.begin(9600); // Open serial port 2
}
void loop()
{
int val = analogRead(0); // Read the value from the analog pin
Serial.println(val); // print to the IDE serial monitor for debugging
Serial2.print(val); // print over serial port 2 to 2nd arduino (Duo)
delay(2);
}
When I read the analog values of the Mega only, using serial monitor, all is well. The analog pin reads as 0-1023
Here’s my code for the Uno read test:
int val = 0;
#include <SoftwareSerial.h> // include the Soft Serial library
SoftwareSerial mySerial (2, 3); // RX, TX. Create a software serial port using pin 2 as RX and pin 3 as TX
void setup()
{
Serial.begin(9600); // Start the inbuilt serial port
mySerial.begin(9600); // start the software serial port
}
void loop(){
int val = mySerial.read(); // read the value being recieved by the software serial port
Serial.println(val); // print the value being recieved by the software serial port,
// using the inbuilt serial port for debugging.
}
So, I connect the Mega to the Uno, however when I connect the TX of the Mega to the RX of the Uno, it seems to power the Uno down the TTL line. Is this normal? I then connect the Uno to USB so that I can read the values being sent on the PC serial monitor. They read as between 48 and 56 depending on the analog input,
I’m sure there’s something I’m doing that’s fundamentally wrong. Any ideas?
Many Thanks
Biffa