Non-blocking I2C + EEPROM

617 views
Skip to first unread message

GianL

unread,
Jul 19, 2013, 8:02:59 AM7/19/13
to mozzi...@googlegroups.com
Hello!

I am working on a little synth based on Mozzi. The idea is to connect 2 Arduino Uno and an EEPROM trough non-blocking I2C. The first arduino (slave) will run one (or more) mozzi oscillators (Oscil) and the second arduino (master) will read a MIDI input and some other inputs and send the values to the slave arduino and to the EEPROM.

Can I use the non-blocking I2C on the slave arduino and the <Wire.h> I2C on the master?
And if it isn't possible can I use the non-blocking version to write and read data to/from the EEPROM?

(I tried to use pieces of the non-blocking I2C example included in the Mozzi library but without success)

Any help (even any piece of sketch) would be appreciated! 

Marije Baalman

unread,
Jul 19, 2013, 8:11:39 AM7/19/13
to mozzi...@googlegroups.com
Hiho,

On Fri, 19 Jul 2013 05:02:59 -0700 (PDT)
GianL <gian....@hotmail.it> wrote:
> I am working on a little synth based on Mozzi. The idea is to connect
> 2 Arduino Uno and an EEPROM trough non-blocking I2C. The first
> arduino (slave) will run one (or more) mozzi oscillators (Oscil) and
> the second arduino (master) will read a MIDI input and some other
> inputs and send the values to the slave arduino and to the EEPROM.
>
> Can I use the non-blocking I2C on the slave arduino and the <Wire.h>
> I2C on the master?
> And if it isn't possible can I use the non-blocking version to write
> and read data to/from the EEPROM?

The slave should use the non-blocking version - since you don't want
audio glitches while it is waiting for I2C to respond.

However, I have only used (and thus written code for) the non-blocking
I2C for a master configuration, you'll have to look up what the
differences are for creating an Arduino I2C slave device, and maybe
adapt existing code for that to make a non-blocking version.

On the master, since you are not doing time-critical stuff, you can use
the regular Wire libray.

> (I tried to use pieces of the non-blocking I2C example included in
> the Mozzi library but without success)

That's probably due to the fact that you want to use i2c as slave, and
not as master.

I hope this puts you on the right track!

sincerely,
Marije

GianL

unread,
Jul 19, 2013, 8:45:13 AM7/19/13
to mozzi...@googlegroups.com
Thank you for your prompt reply
 
you'll have to look up what the
differences are for creating an Arduino I2C slave device, and maybe
adapt existing code for that to make a non-blocking version.

I will try and I will post here the results.

Regards,
Gianluca 
Message has been deleted

Marije Baalman

unread,
Jul 21, 2013, 6:32:44 AM7/21/13
to mozzi...@googlegroups.com
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

Tim Barrass

unread,
Jul 21, 2013, 11:25:15 PM7/21/13
to mozzi...@googlegroups.com
Hi,
I'm going a bit off topic, and it would be best to use I2C for the situation at hand, but this also raises the issue that Mozzi interferes with analogWrite().  I need to add that to the caveats section on the web site and readme.

In Mozzi's STANDARD audio mode, you can use the Timer2 pins, 3 and 11 (look at http://playground.arduino.cc/Main/TimerPWMCheatsheet), but Mozzi takes over Timer0 (pins 5 and 6) and Timer1 (9 and 10).  In HIFI mode, Mozzi uses Timer0, Timer1 (or Timer4 on some boards), and Timer2, so pins 3 and 11 are also out.

If you really need to do PWM (ie. analog write), there is the option to do it on any digital pins using the technique in Mozzi>examples>11.Communication>Sinewave_PWM_pins_HIFI, which is explained here: http://playground.arduino.cc/Main/PWMallPins.

Tim





--
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To post to this group, send an email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/20130721123244.76e1ca2b%40exometheus.

Reply all
Reply to author
Forward
0 new messages