Hiho,
On Sat, 20 Jul 2013 09:45:53 -0700 (PDT)
GianL <
gian....@hotmail.it> wrote:
> I have tried to adapt some pieces of existing code for I2C
> communication but without result.
It is advanced coding, that's for sure.
I would start with getting a regular Arduino to work well with I2C as a
slave; and then work on the non-blocking version, i.e. dig in to the
functions that you use for reading the I2C data and check where the
blocking parts happen (delays, loops waiting for a result, etc).
> So I thought to try another approach to the problem:
> I send some int values to the first arduino (through serial monitor
> while testing) and I write it (analogWrite) on the Analog0 pin;
AnalogWrite is in fact Pulse Width Modulation (PWM). You can only do
this on pins D3, D5, D6, D9, D10 and D11 of a regular arduino. Not on
the Analog0-6 pins, these are for analog reading.
> I
> connected this pin to the Analog0 pin
> of the second arduino, that reads that value and write it on digital3
> pin that is connected to a LED
> (just to check if everything went well).
>
> The result is that for values between 0 and 127 the LED acts as for
> digitalWrite(3,LOW)
> and for higher values as for digitalWrite(3;HIGH)
>
>
> I've checked the sketch many times (and it's also very short) so I
> don't think I've made
> some mistakes in the code.
>
> I wonder if it's a problem of hardware, I mean: if it's possible to
> do what I'm attempting to do.
As I understand it now, this is the path:
serial command to Arduino 1 -> AnalogWrite on a pin -> read with
AnalogRead on Arduion 2 -> control DigitalWrite on a pin
DigitalWrite can only do 1 or 0, so that seems logical even that 0-127
is 0 and 128-255 is 1.
Since AnalogWrite is really PWM I doubt that you can just read in the
value on another Arduino and trust it will be right. You may need to
add a capacitor in there, as a simple filter to actually get a varying
analog voltage out of it. To check you'd need to scope the analog
signal to see what the actual signal (waveform) is that you get.
You should post your code (for both Arduinos) so we can really tell you
where the problem is.
sincerely,
Marije