Go Down

Topic: Arduino Uno Analog O/P (Read 943 times) previous topic - next topic

recordplay

Can my Arduino Uno send Analog out?

DVDdoug

#1
Oct 09, 2019, 12:05 am Last Edit: Oct 09, 2019, 12:11 am by DVDdoug
No.  The regular Arduino does not have a DAC.   

analogWrite() is PWM which can approximate  analog to control the speed of a motor, dim an incandescent lamp,  or to make an LED appear dim.   

There is a tmrPCM library and a PWM DAC library that can get audio using PWM.   But those are not true-analog unless they are properly filtered and I don't think a simple RC filter will do it, and any remaining PWM that "leaks into" an amplifier can do bad things to the amp....

If you want to play "real audio" (voice or music), I'd recommend an audio shield.  These have a memory slot for an SD card, a DAC, a sample-rate clock, and everything else to reproduce audio.   Some versions have an MP3 decoder.    With an audio shield the shield does all of the work and Arduino simply acts as a controller.   

recordplay

No.  The regular Arduino does not have a DAC.   

analogWrite() is PWM which can approximate  analog to control the speed of a motor, dim an incandescent lamp,  or to make an LED appear dim.   

There is a tmrPCM library and a PWM DAC library that can get audio using PWM.   But those are not true-analog unless they are properly filtered and I don't think a simple RC filter will do it, and any remaining PWM that "leaks into" an amplifier can do bad things to the amp....     
Thanks for the reply. So if I wanted to control my modular synth (0-5V) I could use PWM to approximate control from my arduino?

DVDdoug

A low pass RC filter will probably work for that!

Do you know the input impedance of your MIDI device?   The resistor in the filter should be low compared to the input impedance or you won't get the full 5V.    The minimum load on the Arduino is 125 Ohms (any lower and you exceed the current specs) so don't go below that.

The default PWM frequency is about 500Hz so you should be able to filter that out and still respond fast-enough to the MIDI changes.   For example 1K and 1uF gives you a cutoff frequency of 15Hz so you might start with that.

recordplay

#4
Oct 09, 2019, 12:51 am Last Edit: Oct 09, 2019, 12:52 am by recordplay
It's not via midi. It's via analog mono mini jacks pure analog signal 0-5V to input to my symth so would I need to know impedance?

Couldn't I use the RF filter to skim the range down to 0-5V and then just work out a way to get the correct connector out of my Arduino ?


DVDdoug

#5
Oct 09, 2019, 01:18 am Last Edit: Oct 09, 2019, 01:21 am by DVDdoug
Quote
It's via analog mono mini jacks pure analog signal 0-5V to input to my symth so would I need to know impedance?
It would be helpful to know the impedance.   The resistor that's part of the filter and the input impedance make a voltage divider.    For example, if the impedance is 10K and you put a 10K resistor in series, the voltage will drop in half.  A higher value resistor will drop more voltage and a lower resistance will drop less.        

If you have some resistors you can experiment but applying 5V through a resistor to see what happens.    I'd assume the impedance is 10K-100K.

Quote
Couldn't I use the RF filter to skim the range down to 0-5V
It's an RC filter (resistor-capacitor).   The links I gave you explain PWM (pulse width modulation).   The Arduino's output is digital and it puts-out (approximately) zero or 5V.   A narrow pulse has a low average  voltage and a wide pulse has a higher average  voltage.   No pulse is (approximately) zero volts DC.   100% PWM (PWM = 255 on the Arduino) isn't actually PWM, it's (approximately 5VDC).  

The RC filter "smooths out" the voltage to give you a DC voltage at the average (with some "ripple" or "noise " leaking through the filter).  [/quote]


recordplay

Ok, superb. Thanks for the info. Lots of experiments to try. Before I double down on this I wondered if there is an arduino available that does have analog outputs? Can't seem to see one but as there are so many variations I wondered if you know of any that do have true analog outputs

Grumpy_Mike

Quote
Before I double down on this I wondered if there is an arduino available that does have analog outputs?
Yes there are. These are the 3V3 Arduinos like the Due, Zero and MKR boards. But these are of no use to you because they do not cover the full range of voltages, which would only be 0 to 3V3 any way even if you could get the full range.

It is a simple matter to add a D/A converter on your Uno.

recordplay

It is a simple matter to add a D/A converter on your Uno.
Thank you! How do I go about adding a D/A convertor?

Grumpy_Mike


recordplay

Thanks Mike. I've picked up a DAC like you suggested. Now to have a go at breadboarding it!

recordplay

DAC arrived - Attempted to breadboard but initial errors and frustrations.

Connected all cables as they should be - it's more like an issue of loading the code.
Used the ADAfruit code MCP4725 Library - Went through the steps of installing the library. But when I try to load onto my arduino it throws up an error (image attached)


---Error message---

Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Uno"

In file included from /Users/mrvinyl/Documents/[Reference] MANUALS PDFS/Computing/Arduino/Arduino UNO/Adafruit_MCP4725-master/examples/trianglewave/trianglewave.ino:20:0:
Adafruit_MCP4725.h:31:7: error: redefinition of 'class Adafruit_MCP4725'
 class Adafruit_MCP4725{
       ^~~~~~~~~~~~~~~~
In file included from /Users/mrvinyl/Documents/[Reference] MANUALS PDFS/Computing/Arduino/Arduino UNO/Adafruit_MCP4725-master/examples/trianglewave/trianglewave.ino:1:0:
/Users/mrvinyl/Documents/Arduino/libraries/Adafruit_MCP4725-master/Adafruit_MCP4725.h:31:7: note: previous definition of 'class Adafruit_MCP4725'
 class Adafruit_MCP4725{
       ^~~~~~~~~~~~~~~~
Multiple libraries were found for "Adafruit_MCP4725.h"
 Used: /Users/mrvinyl/Documents/Arduino/libraries/Adafruit_MCP4725-master
Multiple libraries were found for "Wire.h"
 Used: /Users/mrvinyl/Library/Arduino15/packages/arduino/hardware/avr/1.8.1/libraries/Wire
exit status 1
redefinition of 'class Adafruit_MCP4725'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



Grumpy_Mike

You should not have the Adafruit libraries in tabs in the main window. They should just be in the libraries folder. Delete those tabs. 

Go Up