Go Down

Topic: I2C EEPROM and audio playback (Read 70 times) previous topic - next topic

mrfsrf

Hi all!
Im hitting the wall here.
I was not sure where to put this post, in Audio section ore here. Sorry if I missed the forum section.

Anyways, What Im trying to achive is to store audio sample (WAV), which is convertetd to char array variable and store it on external eeprom 24LC1024. After that, retrive that variable and play it on small speaker.

Im using PCM.h library for playing, or better to PWM that numbers to pin 11 on arduino where the speaker is connected to.

I have two sketches. One is for writing to eeprom, and the other is fore retriving and playback.


Writing to eeprom is successfull, however, comping the read eeprom sketch gives me error

Code: [Select]
invalid conversion from 'byte {aka unsigned char}' to 'unsigned char*' [-fpermissive]


Does anybody have a clue what am I doing wrong :(
I know it has to do something with <PCM> library, that accepts only pointer to variable.
Any suggestions for other method?
thx!

here is the code




---------- Write.ino
Code: [Select]


#include <Wire.h> //I2C library


  // WARNING: address is a page address, 6-bit end will wrap around
  // also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
  void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage,  unsigned char* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddresspage >> 8)); // MSB
    Wire.write((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
      Wire.write(data[c]);
    Wire.endTransmission();
  }

  void setup()
  {
  
    unsigned char somedata[] = {
    126, 127, 128, 128, 128, 128, 128, 127, 128, 128, 128, 129, 129, 128, 127, 128, 128, 127, 126, 127, 128, 129, 128, 127, 126, 127, 128, 128, 126, 126, 127, 127, 127, 127, 127, 127, 126, 127, 129, 130, 129, 128, 126, 126, 126, 126, 127, 129, 130, 129, 127, 127, 127, 127, 128, 128, 128, 128, 127, 127, 127, 127, 127, 127, 128, 130, 131, 129, 127, 126, 126, 126, 127, 127, 128, 128, 128, 128, 127, 128, 128, 127, 127, 128, 128, 130, 130, 129, 126, 125, 127, 129, 130, 129, 128, 126, 125, 126, 129, 131, 131, 127, 123, 125, 129, 131, 130, 128, 129, 130, 130, 129, 127, 127, 128, 130, 129, 128, 126, 125, 126, 129, 131, 130, 128, 128, 128, 126, 125, 126, 128, 129, 128, 125, 125, 127, 129, 129, 129, 129, 127, 124, 123, 125, 128, 128, 126, 125, 125, 127, 129, 127, 126, 127, 128, 129, 129, 127, 124, 121, 123, 127, 130, 130, 128, 124, 122, 123, 127, 130, 131, 129, 125, 122, 122, 126, 128, 128, 128, 125, 123, 121, 118, 114, 111, 112, 113, 112, 109, 106, 107, 112, 117, 115, 111, 108, 109, 111, 112, 115, 116, 115, 112, 109, 107, 110, 114, 116, 115, 116, 117, 118, 118, 118, 117, 116, 115, 113, 110, 109, 111, 111, 111, 111, 114, 116, 115, 112, 110, 111, 113, 113, 110, 108, 110, 115, 117, 116, 114, 114, 114, 114, 113, 112, 113, 116, 116, 116, 116, 118, 119, 120, 121, 123, 124, 123, 119, 114, 112, 115, 118, 120, 122, 123, 123, 119, 116, 118, 124, 131, 130, 122, 116, 117, 123, 128, 132, 133, 131, 126, 121, 117, 117, 120, 124, 125, 123, 120, 118, 120, 125, 129, 128, 124, 120, 116, 115, 118, 123, 126, 125, 121, 117, 116, 118, 121, 122, 121, 120, 119, 121, 125, 126, 123, 119, 120, 126, 129, 125, 119, 116, 116, 118, 120, 124, 128, 127, 122, 119, 122, 128, 128, 123, 119, 120, 120, 119, 119, 124,
    }; // data to write

    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM

    delay(10); //add a small delay

    Serial.println("Memory written");
    
    
  }

  void loop(){}






---------- Read.ino
Code: [Select]


 /*
  *  Use the I2C bus with EEPROM 24LC64
  *  Sketch:    eeprom.pde
  *  
  *  Author: hkhijhe
  *  Date: 01/10/2010
  *
  *  
  */

  #include <Wire.h> //I2C library
#include <PCM.h>

  byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
     unsigned char rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;
  }
  
  void setup() {}

  void loop()
  {
    
    int addr=0; //first address
    byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (b!=0)
    {
      startPlayback(b)); //playing the sound sample
     // Serial.print((byte)b); //print content to serial port
      addr++; //increase address
      b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    
    //delay(2000);
      

  }





Koepel

Somewhere you use a byte, but the function needs a pointer.
Turn on the line numbers, and have a better look at the error message. The compiler tells you at what line number the problem is.

Whandall

You have to copy the data from the EEPROM to a buffer, before you can pass it to startPlayback.
Probably the EEPROM is much too small to hold any decent sound data, anyway.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

CrossRoads

CDs,which store in WAV format, need 44,100 words (88,200 bytes) to play back 1 channel for 1 second.
How big is 24LC1024?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy