Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Javalin to E-Mic code ... Writing Strings of data into eeProm. — Parallax Forums

Need help with Javalin to E-Mic code ... Writing Strings of data into eeProm.

JMLStamp2pJMLStamp2p Posts: 259
edited 2005-10-11 21:17 in General Discussion
Attention: Peter, Ryan or anyone ! yeah.gif

//Our objective is to send text strings and command codes from the Javelin to the E-Mic Speech Chip.
// Our code is downloading with no syntax errors and the E-Mic chip is being reset correctly due to-
// the soft_Reset method that we are calling.
// Note: our main method also calls methods to receive serial data which is also working correctly.
// We understand that the while statement in the main method will change at a later date.
//We need to fully understand how to load text strings or equivalent values into EEPROM, then send them out to the-
// E-Mic chip along with command codes.

import stamp.core.*;
public class Main_Receiver{

final static int dataPin = CPU.pin4;
static Uart rxUart = new Uart ( Uart.dirReceive, dataPin, Uart.dontInvert, Uart.speed2400, Uart.stop1 );
static StringBuffer buffer = new StringBuffer(128);
static char SpeechCode;
//__________________________________________________________________

final static int Tx = CPU.pin0;
final static int Rx = CPU.pin1;
final static int Busy = CPU.pin2;
final static int Rst = CPU.pin3;
final static int Aout = CPU.pin7;
final static int baud = 396;
final static int TmAdj = 100;
final static int FrAdj = 100;
// final static int char;
final static int eePntr = 0x00;
final static int EOM = 0xAA;
// final static int Say = 0x00;
final static int Volume = 0x01;
final static int Speed = 0x02;
final static int Pitch = 0x03;
final static int Reset = 0x08;
final static boolean buttonOn = false;
final static boolean buttonOff = true;
//_________________________________________________________________________

static void bufferMessage(){
SpeechCode = 0xff;
//treat \r as newline
while (SpeechCode != '\n'){
if (rxUart.byteAvailable()){
SpeechCode = (char)rxUart.receiveByte();
if (SpeechCode == '\r') SpeechCode = '\n';
buffer.append(SpeechCode);

System.out.println((char)SpeechCode); //display incoming message
}
}
}

static void soft_Reset(){
CPU.writePin(CPU.pin3, false);
CPU.delay(10);
CPU.writePin(CPU.pin3, true);
}

static void Init(){
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x01); //Command to set volume
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x06); //Volume set at 06
Check_Busy();
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x02); //Command to set speed
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x02); //Speed set at 02
Check_Busy();
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x03); //Command to set pitch
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x03); //Pitch set at 03
Check_Busy();
}

static void setEEProm(int n){ //have to chop n into bytes
EEPROM.write(0,(byte)(n&0xFE));
EEPROM.write(1,(byte)(n>>8));
}

static int getEEPROM(){
int x;
x=EEPROM.read(1);
x=(x<<8)+EEPROM.read(0);
return x;
}



static void Check_Busy(){
CPU.delay(1000);
// While(CPU.readPin(CPU.pin2));
}


public static void main(){
soft_Reset();
Init();
Check_Busy();
setEEProm(0x42); //this just loads the EEPROM with the decimal equivalent 65, which we want to be the ASCII "A"
System.out.println("Bytes available in EEPROM:");
System.out.println(EEPROM.size());
System.out.println("The value you wrote to EEPROM:");
System.out.println(getEEPROM());
CPU.delay(1000);
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x00); //0x00 is a command for the E-Mic chip to Say( English text)
CPU.shiftOut(CPU.pin0, baud, 8, CPU.PRE_CLOCK_MSB, 0x42); //Here we are trying to have the speech chip "say" the letter "A"
while (true) { //receive and display ALL messages
buffer.clear(); //clear buffer
bufferMessage(); //receive and display one incoming message
}
}
}

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-11 18:14
    Which eeprom do you mean?

    The same eeprom the javelin code is stored in, or an external (I2C) eeprom?

    If it is the javelin eeprom, you can use

    import stamp.core.*;

    EEPROM.write(addr,bytevalue) to store a byte· - start writing at addr 0

    bytevalue = EEPROM.read(addr) to read a byte

    The maximum number of bytes you can write is given by

    int freeEepromSize = EEPROM.size();

    You can also just define static final Strings or char arrays like

    static char[noparse]/noparse cmd1 = new char[noparse]/noparse{0x01,'R','E','S','E','T',0}; //command 1: RESET (example)

    Then use a loop to send the command

    int index= 0;

    while (cmd1[noparse][[/noparse]index]!=0) tx.sendByte(cmd1[noparse][[/noparse]index++]); //send all bytes from cmd1 array



    regards peter
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2005-10-11 18:32
    ·We will try using this code sniplet and see what happens ...

    ·We are using the eeProm in the Javalin ....

    Thanks again ...

    JMLStamp2p roll.gif
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2005-10-11 20:42
    Peter, we are using the character array code from above

    static char[noparse]/noparse cmd1 = new char[noparse]/noparse{0x01,'R','E','S','E','T',0};
    we have this line right below our constants and variables. // is this right?


    while (cmd1[noparse][[/noparse]index]!=0) Tx.sendByte(cmd1[noparse][[/noparse]index++]); //send all bytes from cmd1 array
    we are getting the following error with the "Tx"....
    ...Error: The type of this expression, "int", is not a valid reference type in this context.

    We also would like to know if there is any other literature, besides the Manual, regarding the Javelin Stamp available ???
    We are a lost ball in high weeds at the moment, but we are learning. Thank you for your time and
    patience as usual.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-11 21:03
    The line

    ·while () etc

    must be inside a method (main or other function).

    The char array definition must be outside any function (global definition)

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-11 21:17
    You really should try to make a special emic class to hide all emic details.

    For example, the emic is a speech synthesizer, so it would make sense to

    create a package stamp.peripheral.sound.speech.emic

    You do that by entering the folder %path%/lib/stamp/peripheral

    There you make a folder sound

    In folder sound you make a folder speech

    In folder speech you make a folder emic

    Now create a new javelin file

    package stamp.peripheral.sound.speech.emic;

    import stamp.core.*;

    public class Emic {

    · //constructor

    · //assuming interface is bidrectional uart

    · private Uart tx;

    · private Uart rx;

    · public Emic(Uart tx, Uart rx) {

    ··· this.tx = tx;

    ··· this.rx = rx;

    · }

    · public void reset() {

    ··· //reset code

    · }

    · //other functions for the emic

    }



    In your main class file

    import stamp.peripheral.sound.speech.emic.*;

    static Uart emicTx = new Uart(Uart.dirTransmit...); //complete this

    static Uart emicRx = new Uart(Uart.dirReceive...); //complete this

    static Emic myEmic = new Emic(emicTx,emicRx); //define your emic



    accessing your emic from your main application file now consists only

    of calls like myEmic.reset() etc.

    This way your main class file remains clean of details for peripheral interfaces.

    It also allows you to add more Emic chips in seconds by just defining another Emic.



    regards peter
Sign In or Register to comment.