I am working on an arduino synthesizer and I plan on being able to use multiple modules together. Part of this would require me to be able to read the analog and digital voltage from one to another.
What would be the way to go about connecting the two? Would I just need to connect both grounds together to complete the circuit?
Sorry if this is a newb question. I don't know much about electronics.
maybe u could just connect them via their I2C pins?
u could just connect 1 digital pin of arduino#1(transmitter) to arduino#2(receiver) and say "beeeepbeep" for "1" and "beepbeeeep" for "0" and "beeeeeeeepbeeeeeeeep" for "start of transmission" and "beepbeep" for "end of transmission"...
where the first "beep"/"beeeep" is HIGH and the second is LOW and the number of "e"s denote the length of the signal...
Sadly since I am generating two square waves at once already on the synthesizer arduino I cannot afford to have many loops within it for data transfer.
Imagine that I have two units. To keep it simple, one unit is generating a square wave at a rate that's based on how much voltage is coming from a call to analogRead() on a ANALOG IN pin. The other unit is providing a sequence of voltages (let's just say I'm using PWM to make it easy) that will be sent to this pin.
From the sound of it, if I want it to work, I just need to connect a PWM voltage of one arduino to another's ANALOG IN pins and also connect each other to the same ground.
I'm pretty sure you answered it already but I wanted to clear up any confusion. So thanks!
I just need to connect a PWM voltage of one arduino to another's ANALOG IN pins and also connect each other to the same ground.
Alas, no, it's not that simple.
You'll need to filter that PWM output to turn it into an analog signal. Otherwise, the second Arduino will just see a "0" or a "1023", depending on where in the PWM cycle it samples the input.
If you're not using that analog output for some other purpose, it would be much better to communicate the digital value using a mechanism like the serial port or I2C (the Wire library). Otherwise, you're definitely going to lose some accuracy getting the signal from one CPU to the other, and it may be enough to cause problems.
The serial port has a buffered receive that will accumulate data "in the background", so it can be used with minimal disruption of your square wave generation.
Ah well I already have done something like this. The analog outputs of what I have so far are constant, they are not using PWM. I was hoping the PWM example would have been easier but I wasn't thinking about how they actually work.
I must thank you, though, for answering another question I've had in my head for a while about serial and how it accumulates data. Of course if by "in the background" you mean that it doesn't interrupt the loop. Maybe I am just biased because whenever I'm debugging and use Serial.println() I get some tick sounds in my output (as in it's taking a while to execute the printing code).
Only serial input is buffered and interrupt-driven: the output code is blocking, only transmits one character at a time as the hardware transmit register empties, and will tie up the CPU until everything is sent.
There's some discussion going on about adding a transmit buffer, now that many people are moving to the ATMega328 with more RAM. But it hasn't been done (or even started, as far as I know) yet.