November 26, 2024, 10:21:58 AM

MOD-IO2 DAC OUTPUT

Started by reet, April 27, 2022, 03:00:10 AM

Previous topic - Next topic

reet

I want to read the analog output by enabling and configuring DAC. I tried by setting the SET_DAC(0x60) command, however, I was unable to read the analog data.

I am using Olimex MOD-IO2 with Arduino Uno using I2C communication.

The code used is as follows:

#include <Wire.h>
#include <IO2.h>
// Control MOD-IO2 at address 0x21
IO2 io2(0x21);
void setup () {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(0x21);       //Address
  Wire.write(0x60);                  //Set DAC command
  Wire.write(0x1F);                  //Value
  Wire.endTransmission();
  io2.pinMode(io2.GPIO2, io2.OUT);   //Configured GPIO2 as OUTPUT
}

void loop () {
  uint8_t data;
  data = analogRead(io2.GPIO2);
  Serial.println(data);
  delay(100);
}

Please guide and also let me know what changes needs to be done in the code.
Thanks!
 

LubOlimex

> I was unable to read the analog data.

Where and how are you reading the data? With external tool or are you trying to use a DAC as ADC?
Technical support and documentation manager at Olimex

reet

I am trying to read data on the Oscilloscope connected to GPIO2.
Also, I want to know if I need to set DACOUT1 in the code or is it done in the firmware 4.3

LubOlimex

What is the version of the firmware? Can you read it? 0x21 is the command code to read the current firmware - what does it return? The code should look something like:


int firmware_version;
Wire.begin();
Wire.beginTransmission(0x21); // address
Wire.write(0x21); // version code
Wire.endTransmission();
Wire.requestFrom((int)0x21, 1);
firmware_version = Wire.read();
Serial.println (firmware_version);
Technical support and documentation manager at Olimex

reet

I executed the above code and it returns the firmware revision 40.
Can you check my first post whether I am using the command in correct way?
The main purpose is that I want to have an analog output in range of 0 to 5V from GPIO2.

reet

As per README.pdf given in the firmware folder, it is mentioned that "Set DACOUT1 and configure GPIO2 as analog output" Is this done in firmware or have to do it? If it is to be done then can you please explain how?

LubOlimex

OK at least it is clear why the DAC function does not work. This is not the latest firmware, it has no DAC function which was added in the last release (firmware 4.3). You need to upgrade the firmware with the binary of the last firmware from the web-page of the device. To upgrade you need a PIC-compatible programmer and fitting for the 6-pin ICSP connector cable.

The analog output can't be in the 0-5V range. It is from 0 to around 3.2V. This is also mentioned in the documentation.
Technical support and documentation manager at Olimex

reet

The firmware revision code returned 64. Is it the correct revision?

LubOlimex

No. This is the previous version that has no DAC function.

The correct version should return 67 (43).
Technical support and documentation manager at Olimex