Notifications
Clear all

Connected a DAC to an Arduino Uno

26 Posts
5 Users
0 Likes
7,578 Views
(@frenchstudent)
Member
Joined: 5 years ago
Posts: 5
Topic starter  

Hey everybody, 

I'm currently on secondary school in French Academy and i discovered The Arduino and I²C one month ago. My project deals with the creation of an audio beam system with 8 speakers. I need to connect a DAC MAX 5825 to my Arduino Uno to create different sounds if the sound comes from the back or the front. My main difficulty is to write the I²C code to connect them.

I'm trying to understand the I²C bus but it's totally new for me and i don't understand all.

 

Thanks everybody for your attention.


   
Quote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@frenchstudent

If I were you I would start by reading about the Wire.h library and the associated functions on the Arduino Website.

https://www.arduino.cc/en/Reference/Wire

You might want to bear in mind that the Arduino Uno cannot be further than 1 metre from the I2C module that you are communicating with. If the connecting wires are more than 1 metre, the data transfer becomes unstable.


   
ReplyQuote
(@frenchstudent)
Member
Joined: 5 years ago
Posts: 5
Topic starter  

I already read the library but i never used this language so it is complicated to begin with. Nevertheless i succeeded to do the basics on the I²C but in some videos and commentary i saw only the connection between 2 Arduino Uno board and for me i just need to connect to a DAC. But i can't give some instructions to the DAC, so is it always a slaveor not?


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@frenchstudent In addition to Pugwash advice, this pdf presents the I2C bus.

And you may also want to have a look at the source code of another DAC/I2C library like miniDAC (available in the Arduino IDE libraries)

...et bonjour d'un autre français !

 

Eric


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

and these guys seem to be using the same thing as you : http://forum.aemodular.com/post/2980/thread

 

Eric


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@frenchstudent, @zeferby

Is your MAX 5825 mounted on a breakout board or do you just have the SMD chip?

You basically need something like 

Wire.begin();
Wire.beginTransmission();
Wire.write(i2c_address, address, value); //the address will be the channel
Wire.endTransmission();

I have looked but can't find how the addressing works!

By the way, sorry guys about Japan. I am Welsh and I think the better team lost! 


   
ReplyQuote
(@frenchstudent)
Member
Joined: 5 years ago
Posts: 5
Topic starter  

@zeferby @pugwash

Thank you for the different link, i'll read it. On peut parler en français si nécessaire.

 

My MAX 5825 is on a breakout board.  I already write it : 

 

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Adress
#define SLAVE 9

void setup() {
// put your setup code here, to run once:
// Initialize I2C communictions as Master
Wire.begin();

//Setup serial monitor
Serial.begin(9600);
Serial.println("I2C MASTER DEMONSTRATION");
}

void loop() {
// put your main code here, to run repeatedly:
delay(50);
Serial.println("Write data to slave");

// Write a character to the Slave
Wire.beginTransmission(SLAVE);
Wire.write(0);
Wire.endTransmission();

Serial.println("Receive data");

 

Yeah i'm totally disappointed about the results. It's so sad because i thought that France will loose the cup against an other team and further in the championship.

 


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@pugwash @frenchstudent

The Wire reference on Arduino's web is at https://www.arduino.cc/en/Reference/Wire  

Reading the datasheet, I think it may need to be something like :

 

byte byteArray[3];

byteArray[0] = max5828_command;
byteArray[1] = max5825_data_high;
byteArray[2] = max5825_data_low;

Wire.begin();
Wire.beginTransmission(max5825_i2c_address);
Wire.write(byteArray, 3);
Wire.endTransmission();

 

Maybe you could also try the variant which sends a Stop and releases the I2C bus :

Wire.endTransmission(true);

 

...and thanks @pugwash

Eric


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

Also in the aemodular.com forum post above I read : "Ah! Found it! Page 25!!! "CODEn" sets the value for each DAC"

Eric


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

I took a look at the datasheet attached.

https://datasheets.maximintegrated.com/en/ds/MAX5823-MAX5825.pdf

I need to take at least a week to digest it! ? 


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

   
ReplyQuote
(@frenchstudent)
Member
Joined: 5 years ago
Posts: 5
Topic starter  

@ZeFerby

Thank you about the datasheet. I read it and i start to understand how the DAC works and the same for I²C adress. Nevertheless i don't understand how i can use it in the Arduino code. I think it comes from the fact i dont have a good level in electronics but i'm interesting in.

 

@pugwash

I understand that you register all your different information to use it later. But my main problem is to create the code on the Arduino...


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@frenchstudent

I understand that you register all your different information to use it later. But my main problem is to create the code on the Arduino...

Well, I am afraid you are going to have to go through the same learning process as the rest of us.

The way I see it is, that I2C programming is the easy part. Having read the same datasheet as you guys, I am unable to decipher the addressing method of the MAX 5825.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@frenchstudent

I must add that hooking up a MAX5825 to an Arduino, as your first project, is very brave but not very wise. This is very much trying to run before you can walk.

I don't wish to sound cruel but nobody here is going to write the code for you.

As for the sample code I posted above, the writeToRegister() function or an adaptation, is fundamentally all you need to send data via I2C once the communication protocol has been initiated. And it doesn't matter where the data is coming from, array or sensor or anything else putting out digital values!


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
@frenchstudent
 
Actually I think like @pugwash that your I2C slave address of 0x09 is highly suspicious...maybe coming from one of Bill's samples in this article/video ? https://dronebotworkshop.com/i2c-part-2-build-i2c-sensor/  
 
The first thing you need is being sure of the I2C address of your device : use one of the I2C scanners listed there : https://forum.dronebotworkshop.com/sensors-modules/i2c-addresses-scanners-and-other-infos/
 
Posted by: @pugwash

Well, I am afraid you are going to have to go through the same learning process as the rest of us.

Well...i have bad news...it may take some time...

 

42 !

Eric


   
ReplyQuote
Page 1 / 2