Go Down

Topic: sending audo via I2C (Read 1 time) previous topic - next topic

falexandru

I mounted a touch sensor on Arduino UNO-  OK (on digital pin - I have to find a way to mount it on I2C but this is a different story).

I also mounted 4 external EEPROMs on the same I2C and managed to address them.

I mounted a LCD on same I2C.

So far, so good - all OK.

I mounted a DAC and an amplifer, as well a 0,35 W 8 Ohm loudspeaker, on I2C (the sanner found the DAC on 00 address, which is strange, but I do not care.

Components are:
- Amplifier based onLM386
https://www.optimusdigital.ro/electronica-de-putere-amplificatoare-audio/45-amplificator-audio-lm386.html?search_query=LM386&results=3
- DAC/CAD
https://www.optimusdigital.ro/altele/1327-modul-dac-mcp4725-cu-interfaa-i2c.html?search_query=DAC&results=183

The above are components of my Robo-cat.

The Robo-cat function I am working on is:  Meow when petted.

Question is:

How can I send audio via I2C?


More precisely, is there any simple code to cut the wav (that is un-compressed but perhaps midi may work to, I do not know) in 8 b slices, put them to eeprom, read them from there and send via I2C?

++++

I know it is going to be slow and awful, but I need the cat to meow, not to play Mozart  :) .

Thank you everyone, cat-lovers or not  :)

el_supremo

Quote
the sanner found the DAC on 00 address, which is strange, but I do not care
You should care. The datasheet says that the device's I2C address can be one of 0x60 - 0x67.

Pete
Don't send me technical questions via Private Message.

falexandru

You should care. The datasheet says that the device's I2C address can be one of 0x60 - 0x67.

Pete
Oh! I thought is just another address. It happened to my LCD - different address spotted by the I2C scanner than the one in the datasheet.

The Internet says it is not possible to use address 0x00 on I2C. But I got it.

What does it mean then?

el_supremo

Specifically which I2C scanner did you use?

The scanners I have seen don't search for address zero.

Pete
Don't send me technical questions via Private Message.

falexandru

Code: [Select]
 



// i2c_scanner
 //
 // This program (or code that looks like it)
 // can be found in many places.
 // For example on the Arduino.cc forum.
 // The original author is not know.
 //
 // This sketch tests the standard 7-bit addresses
 // from 0 to 127. Devices with higher bit address
 // might not be seen properly.
 //
 // Adapted to be as simple as possible by Arduino.cc user Krodal
 //
 // June 2012
 // Using Arduino 1.0.1
 //
 
#include <Wire.h>
 
void setup()
 {
   Wire.begin();
 
  Serial.begin(115200);
   Serial.println("\nI2C Scanner");
 }
 
void loop()
 {
   byte error, address;
   int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
   for(address = 0; address <= 127; address++ )
  {
     // The i2c_scanner uses the return value of
     // the Write.endTransmisstion to see if
     // a device did acknowledge to the address.
     Wire.beginTransmission(address);
     error = Wire.endTransmission();
 
    if (error == 0)
     {
       Serial.print("I2C device found at address 0x");
       if (address<16)
        Serial.print("0");
       Serial.print(address,HEX);
       Serial.println(" !");
 
      nDevices++;
     }
     else if (error==4)
    {
       Serial.print("Unknow error at address 0x");
       if (address<16)
        Serial.print("0");
       Serial.println(address,HEX);
     }
   }
   if (nDevices == 0)
     Serial.println("No I2C devices found\n");
   else
     Serial.println("done\n");
 
  delay(8000);           // wait 8 seconds for next scan
 }
 



falexandru

..and here is the result of I2C scanning by the above sketch - attached.

el_supremo

#6
Jul 08, 2017, 05:53 pm Last Edit: Jul 08, 2017, 05:56 pm by el_supremo
The output from the serial monitor can be cut and pasted as ordinary text between code tags. It's a lot easier for all concerned.

That code is checking address zero. It shouldn't do that. IIRC, address zero is a broadcast address and any device on the bus can respond. If you have more than one device on the bus (e.g. LCD or EEPROM) one of those has responded. If you don't get the correct non-zero address, that device isn't wired properly.

BUT, the DAC did answer with address 0x60. 0x51,53,56,57 are the EEPROMs and, presumably, 0x3F is the LCD. All looks good.

Pete
Don't send me technical questions via Private Message.

falexandru

"BUT, the DAC did answer with address 0x60. 0x51,53,56,57 are the EEPROMs and, presumably, 0x3F is the LCD. All looks good."

Thanks!

It is still enigmatic why the scanner returns 0x00 only when I connect the DAC. If I wire only EEPROMs and LCD, no 0x00 appears   :smiley-confuse:

falexandru

..and thanks for the tip on copy/paste serial monitor!

DVDdoug

#9
Jul 08, 2017, 06:11 pm Last Edit: Jul 08, 2017, 06:31 pm by DVDdoug
I can't answer your question, but certainly you have to "clock-in" the data at the correct audio sample rate, depending on the files/data stored in your EEPROMs.

Quote
More precisely, is there any simple code to cut the wav
That's up to you.  There's no "file structure" or file names in an EEPROM or flash chip.*  You read the bytes by knowing the address of the data.  There's no standard way of storing audio in a memory chip.

But, a WAV file is simply a sequence of bytes, and that byte-sequence can be copied as a sequence of bytes into an EEPROM or flash chip, or RAM (basically as an array).    The sequence and "meaning" of the bytes depends on the bit-depth and number of channels, and that's all defined in the header.

In your case, you already know all of those details so you can throw-away the header if you wish.

Quote
midi may work to
No...  Not unless you have a MIDI instrument (in hardware or software).     

MIDI is not "sound".  MIDI is "notes & timing"...  I call it "sheet music for the computer".   You can play a MIDI file and configure your MIDI instrument to sound like a trumpet or like a guitar.   (Although, there is "instrument" information in the MIDI file so the correct virtual instrument gets played by default.)




* Thumb drives and solid state drives are made with flash chips, but there's more to the drive than just a memory chip or two...

Go Up