An Uno doesn't read what the Mega sends.

Hi all,

I was playing around with my arduinos and tried to read an analog output from an Uno into a Mega but i don't get it to work.
And i cant find out why


Uno AnalogWrites the Mega AnalogReads

Sending code for the Uno

// Sending code for the Uno
int sensePin =0;
int OutPin =9;

void setup(){
  pinMode(OutPin, OUTPUT);  
}

void loop(){
  int val = analogRead(sensePin);
  int OutLevel = map(val, 0, 2024, 0, 256);
   
  analogWrite(OutPin, OutLevel);
}

Receiving code for the Mega

//Receiving code for the Mega
int sensePin =0;
int LedPin =9;

void setup(){
  pinMode(LedPin, OUTPUT);
}

void loop(){
  int val = analogRead(sensePin);
  int LedLevel = map(val, 0, 2024, 0, 256);
  
  analogWrite(LedPin, LedLevel);

When I watch the input from the pot trouth the serial monitor on the uno, it go's from 0 to 2024
When I watch the output on the Mega it gives me 0 or 2024 but nothing in between.

Have fun
Greetings Sjuul

Despite their names analogRead and analogWrite do different things. analogRead reads a voltage level (ADC conversion), analogWrite does PWM modulation. If you used a resistor and a capacitor as a RC filter it might help.

I'd suggest using some digital like Serial or SoftwareSerial to share information between
boards. Analog voltages are imprecise, easily pick up noise, different boards have slightly
different supply voltages and as has been mentioned analogWrite is only 'analog' in mark-
space ratio, not instantaneous voltage.

Thanks Nick & Mark,
You made it perfectly clear for me. I was trying this because I want to transmit a signal without using the I2C. The mega reads 3 quadrature encoder signals so al the interrupts and I2C pins are in use. I wanted to use the Uno I had laying around to measure an RPM and then sending it analog to the mega.
This way I can visualize the 3 encoder positions and the rpm on one 4x20LCD
That is my challenge …

Could you send the value by varying the width of a pulse transmitted by the Uno and using pulsein() to measure the width on the Mega?

…R

Don't you have a spare serial port? This sounds rather obscure.

I2C pins are in use

By what?

Mega2560 specs:
I2C: pin20 (SDA) and pin21 (SCL)
Interrupts: pin2, pin3, pin21, pin20, pin19, pin18

That doesn't exactly answer my question. What are you using those pins for?

Im making a Digital read out and RPM sensor for my mill
On my channel you find a short clip of the project so fare

The code (to long to post):
Arduino_Powered_DRO_04_10_2013