I have an arduino application handling a rotary encoder. In the script, I'm using PWM to output values to pin 7 on the Arduino Mega. I then have Pin 7 and Ground on the Arduino going to Analog Pin 7 on the Bela and the Ground near the analog input.

Here is the line from the Arduino script that's controlling the power value.
analogWrite(analogWritePin, value); // analogWrite values from 0 to 255

If I plug this into a multimeter, the Arduino is properly outputing the 5v power based on my rotary encoder.

I'd like to use that to control the volume of a sound file looping in PureData. Here is what I have now:

Anyway to do this? Right now I'm not getting any sound out of the PureData sketch.

The output from the Arduino is likely a PWM signal (i.e.: a digital signal that sends out a stream of 0 or 1, such that the average of the signal matches the desired analog value). This cannot really be read from Bela's analog input unless you add a simple analog filter to turn the stream of zeros and ones into a continuous voltage. Something like this should work:

Arduino             Bela
PWM out -- R --+----analog in
               |
               C
               |
              GND

with R = 10k and C = 10n or equivalently R = 1k and C= 100n you'd get a cutoff of about 1.5kHz which should be appropriate.

Thank you. It worked. But to my ears, R = 10k and C = 1uf sounded the best.

11 days later

What if I wanted to send a digital signal instead? I assume I'd have to use 3.3v out of the Arduino or a logic shifter. Anything else I'd need to do to wire it differently?

Not sure if 5V Arduinos have 3.3V outputs? If you have a 5V output and you want to connect it to a 3.3V input you can use a resistor divider instead of a level shifter, e.g.L:

Arduino 5V            Bela 3.3V
dig out ---- R1 --+--digital in 
                  |
                  R2
                  | 
AGND ----------- GND------BGND

where approximately R2/(R1+R2) = 3.3V/5V and the values are i the kiloohm range, e.g.: R2 = 4k7, R1 = 2k7 will give a good 3.18V there.

a month later

Actually, I was planning on pulling the LED pinout of the SparkFun capacitive touch breakout board. https://www.sparkfun.com/products/12041

So if I get the ground line and the LED line out of the SparkFun board, I get 3.3v to my multimeter if I'm touching the capacitive touch board. How would I connect that to bela for digital input?

Chris

You just need to provide a power source (1.8V--5V)

so power it with 3.3V and you get a 3.3V output that you can connect directly to a Bela digital input.