Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 20, 2011, 01:29:44 pm
I just realized that the function sendCommand can take decimals as well since hex and decimals make no difference....

so if i want to play the 254th song, which is 0xfe in hex, I don't even need to convert
just do sendCommand(253)

blindly following examples is not good...smiley-sad
2  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 20, 2011, 12:48:04 pm
the 254th song is 0x0253 in hex. The program will send 'a253'
3  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 20, 2011, 12:22:56 pm
I guess i wasn't clear enough. There is technically no user, as in a human being. Only a program will send inputs over, so invalid inputs will not happen unless I code my program erroneously. Also only decimals are entered, no hex, just like I've been doing in my examples. I have a database of what each file,  so going by decimal is simplest.

I see your point on flush, and I realized that I never utilized the busy pin. So by adding the following I should fix some issues:

Code:
sprintf(text, "0x%d", total);
                total=strtol(text,NULL,0);
                sendCommand(total);
               int readPin= digitalRead(busyPin);
                while(readPin==HIGH){
delay(1000);
                }
;

this way I can pile up a bunch of a342a128a300 and still be fine.
4  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 19, 2011, 04:32:29 pm
is there a problem for having a flush there? say someone enters a342d, wouldn't the flush help to get rid of the d, which is irrelevant and useless?

as for previous songs. I don't have the need for calling those. The only thing that matters to me is the ability to call specific files.
5  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 19, 2011, 12:32:28 pm
so I moved the flush to after, though honestly I was writing the code thinking that I would have the "user" input an a and then send the other stuff after a delay. But your way makes much more sense.

As for the hex, yes I realize that they don't equate in that way. I was trying to achieve the following:

-the user enters a400
-arduino gets 400 and gets it as a text "0x400"
-strtol to a real hex

seem right? Attached is the corrected code
Code:
int total=0;
char text[6];
const int clockPin = 2;  // the pin number of the clock pin
const int dataPin = 3;  // the pin number of the data pin
const int busyPin = 4;  // the pin number of the busy pin
const int resetPin = 5;  // the pin number of the reset pin


const unsigned int VOLUME_7 = 0xFFF7;
const unsigned int STOP = 0xFFFF;

void setup(){

 Serial.begin(9600);
pinMode(clockPin, OUTPUT);
   pinMode(dataPin, OUTPUT);
        pinMode(busyPin, INPUT);
   pinMode(resetPin, OUTPUT);
        digitalWrite(clockPin, HIGH);
   digitalWrite(dataPin, LOW);
// reset the module
        digitalWrite(resetPin, HIGH);
        delay(100);
        digitalWrite(resetPin, LOW);
        delay(10);
        digitalWrite(resetPin, HIGH);
        delay(100);

  sendCommand(VOLUME_7);

}

void loop(){
if (Serial.available() > 0) {
    int moveServo = Serial.read();
 
     if (moveServo =='a'){
//audio begins, stop haros movement and start looping    
myservo.write(94);
//get first 3 bit of incoming data 001-500 for file name
while(Serial.available()<3){
}
for(int i=0;i<3;i++){
//gets decimal concat, ignores 0’s on left
total=total*10+Serial.read();
}
                sprintf(text, "0x%d", total);
                total=strtol(text,NULL,0);
                sendCommand(total);
delay(1000);


       }

    Serial.flush();

}
void sendCommand(unsigned int command) {
  // start bit
  digitalWrite(clockPin, LOW);
  delay(2);

  // bit15, bit14, ... bit0
  for (unsigned int mask = 0x8000; mask > 0; mask >>= 1) {
    if (command & mask) {
      digitalWrite(dataPin, HIGH);
    }
    else {
      digitalWrite(dataPin, LOW);
    }
    // clock low
    digitalWrite(clockPin, LOW);
    delayMicroseconds(200);

    // clock high
    digitalWrite(clockPin, HIGH);
    delayMicroseconds(200);
  }
  // stop bit
  delay(2);
}
6  Using Arduino / Programming Questions / Re: Sketch for making audio sound module work on: September 16, 2011, 11:42:50 am
i just want to get the first incoming byte of data so later on if the user enters 'a', I can read the only 3 bytes off the serial. I don't quite get what you saw was problematic there sorry.

For the 3 incoming bytes, say I received 4, then 1, then 2
my code concatenates this to become 412.
What I wanted to do was to take this 412 and make it into 0x412. I should be doing this I guess:
Code:
sprintf(text, "0x%X", total);
strtol(text,&total,10)
sendCommand(total);
I wrote all this up for the algorithm and didn't have the hardware or software on hand to test.
7  Using Arduino / Programming Questions / Sketch for making audio sound module work on: September 15, 2011, 07:40:25 pm
hey guys,

   Can you guys take a look at the sketch I wrote for the arduino + sparkfun's audio sound module(http://www.sparkfun.com/products/9534
)? Basically since the module plays files named 0x0001 to 0x0500, I am making a sketch that takes 3 numbers that tell the module which file to play. First I concatenate those 3 numbers as decimals since 0's on the left can be ignored once I convert to hex. Then I sprintf it hex. I'm not quite sure if my syntax is right or if this is the right approach. I based my code largely off
http://yapan.googlecode.com/svn/trunk/arduino/examples/SOMO_14D_Test/SOMO_14D_Test.pde

Code:
int total=0;
char buf[8]={0};
const int clockPin = 2;  // the pin number of the clock pin
const int dataPin = 3;  // the pin number of the data pin
const int busyPin = 4;  // the pin number of the busy pin
const int resetPin = 5;  // the pin number of the reset pin


const unsigned int VOLUME_7 = 0xFFF7;
const unsigned int STOP = 0xFFFF;

void setup(){

 Serial.begin(9600);
pinMode(clockPin, OUTPUT);
   pinMode(dataPin, OUTPUT);
        pinMode(busyPin, INPUT);
   pinMode(resetPin, OUTPUT);
        digitalWrite(clockPin, HIGH);
   digitalWrite(dataPin, LOW);
// reset the module
        digitalWrite(resetPin, HIGH);
        delay(100);
        digitalWrite(resetPin, LOW);
        delay(10);
        digitalWrite(resetPin, HIGH);
        delay(100);

  sendCommand(VOLUME_7);

}

void loop(){
if (Serial.available() > 0) {
    int moveServo = Serial.read();
    Serial.flush();
 
     if (moveServo =='a'){
//audio begins, stop haros movement and start looping    
myservo.write(94);
//get first 3 bit of incoming data 001-500 for file name
while(Serial.available()<3){
}
for(int i=0;i<3;i++){
//gets decimal concat, ignores 0’s on left
total=total*10+Serial.read();
}
                sprintf(buf,%X",total)
sendCommand(buf);
delay(1000);


       }


}
void sendCommand(unsigned int command) {
  // start bit
  digitalWrite(clockPin, LOW);
  delay(2);

  // bit15, bit14, ... bit0
  for (unsigned int mask = 0x8000; mask > 0; mask >>= 1) {
    if (command & mask) {
      digitalWrite(dataPin, HIGH);
    }
    else {
      digitalWrite(dataPin, LOW);
    }
    // clock low
    digitalWrite(clockPin, LOW);
    delayMicroseconds(200);

    // clock high
    digitalWrite(clockPin, HIGH);
    delayMicroseconds(200);
  }
  // stop bit
  delay(2);
}

thanks for the help
8  Using Arduino / Networking, Protocols, and Devices / Re: Replacing serial connection with bluetooth on: September 13, 2011, 01:14:05 pm
hmm yea that makes sense, its really a pain how they interfere with each other. I've heard that its possible to program the arduino via smirf, but it seems quite a bit of trouble for my purposes.
Just so I'm completely in the clear in my sketch, here it is, nothing sticks out like a sore thumb i hope?
Code:
#include <Servo.h>
const int servoPin =  9;    // control pin for servo motor
Servo myservo;
int angle = 86;

void setup()
{
  myservo.attach(servoPin);
  myservo.write(angle);
  Serial.begin(9600);
//com port 12 and 13 are supposedly the serial ports to my bluetooth, or at least my bluetooth software tells me. I
      // Serial.println("AT+BTCLT=0011E00*****,12");
             Serial.println("AT+BTSRV=12");

}

void loop()
{
  if (Serial.available() > 0) {
    int moveServo = Serial.read();
   //1-0,2-30,3-60,4-90,5-120,6-150,7-180
    if (moveServo == '1') {
     angle =0;
    }
    if (moveServo == '2') {  
     angle =30;
   }
     .... more of the same
     if (moveServo == '7') {  
     angle =180;
    }
    angle = constrain (angle, 0, 180);
    myservo.write(angle);
  }
}

I decided to go with AT+BTSRV since it turns on discovery and allows me to pair, where AT+BTCLT just goes for a connection. I assume that since the smirf is server that my computer's bluetooth would/can be configured for auto-reconnect?

When the arduino is on and disconnected from the usb, I will pair with it and connect from my computer. If I do this, port 12 hopefully would be connected and I would be able to send chars through hyperterminal to the arduino. Does it seem like this would be fine? I fear of hidden settings that would make this not work, nothing ever works out smoothly as planned :/

Thank you for the help

tianshiz
9  Using Arduino / General Electronics / raw power supply unable to power smirf on: September 13, 2011, 12:22:25 pm
I have an arduino pro mini that I have been powering through an usb breakoutboard that gives it 3.3v voltage supply. This setup works fine and my attached smirf is functional. But once I removed the usb and instead power the arduino through my raw pin using a coin cell(3.3v), the arduino turns on but the smirf is off.  I recall the coincell working long ago on the arduino and smirf setup, what could be the problem here?
10  Using Arduino / Networking, Protocols, and Devices / Re: Replacing serial connection with bluetooth on: September 13, 2011, 12:17:48 pm
that is probably it, the only time that my BTCLT command worked was when I had them paired. I removed the pair foolishly since it didn't seem like my computer recognized a connection after the BTCLT connected.
Aside from that though, I'm also suspecting a problem from my circuit setup. I have both the bluesmirf and a usb breakout board attached to my arduino, having them both attached prevents me from uploading sketches. Does it also prevent the bluetooth from connecting as well?
11  Using Arduino / Networking, Protocols, and Devices / Replacing serial connection with bluetooth on: September 12, 2011, 12:22:21 pm
hey guys,

  I'm having some issues altering my sketch  to make my arduino connect wirelessly through serial to my pc. Ultimately I want to be able to send a character on hyperterminal and have the arduino receive it and perform an action. Right now I can do this with a physical serial connection, the problem is the wireless. I'm using the bluesmirf silver v2.

For some reason the bluesmirf always starts up in command mode so I have to send an AT command to put it into data mode. The most successful method seems to be :

       Serial.println("AT+BTCLT=address,port");

That is the only line I add into setup(), right after "Serial.begin(9600);". I tried various ports, and most of them wouldn't work. Though port 1 turned on the green connection light on the smirf, my computer didn't recognize the connection and I do not have a com port 1 on my computer :/ What am I misunderstanding here?

Thanks
12  Using Arduino / General Electronics / Re: continuous servo refuses to rotate any other direction on: September 07, 2011, 12:24:50 pm
just got some new servos, hopefully it works out this time. Just to make sure I did a rough sketch of my setup, does there seem to be any problems? I don't want to burn another servo again... the code I'm using is the one in my previous post. Thanks!
13  Using Arduino / General Electronics / Re: continuous servo refuses to rotate any other direction on: September 02, 2011, 09:12:21 pm
connecting the ground worked, but after testing a little bit while, the strangest thing happened, everything just stopped working again. I can hear a low hum from the servo, but that's it.

here's my code:
Code:
#include <Servo.h>
const int servoPin =  3;    // control pin for servo motor
Servo myservo;
int angle = 90;

void setup()
{
  myservo.attach(servoPin);
  myservo.write(angle);
  Serial.begin(115200);

}

void loop()
{
  if (Serial.available() > 0) {
    int moveServo = Serial.read();
   //1-0,2-30,3-60,4-90,5-120,6-150,7-180
    if (moveServo == '1') {
     angle =0;
    }
    if (moveServo == '2') {  
     angle =30;
   }
    if (moveServo == '3') {  
     angle =60;
    }
     if (moveServo == '4') {  
     angle =94;
    }
     if (moveServo == '5') {  
     angle =120;
    }
     if (moveServo == '6') {  
     angle =150;
    }
     if (moveServo == '7') {  
     angle =180;
    }

    


    Serial.print("Angle: ");
    Serial.print(angle);

    myservo.write(angle);
  }
}

I checked the power src for the servo, and its still 5v no problems, and the connections all seem fine...
14  Using Arduino / General Electronics / Re: continuous servo refuses to rotate any other direction on: September 02, 2011, 11:57:26 am
wow that would explain it,  smiley-red i'll try that get back to you guys. hopefully my miswiring didn't mess up the servo
15  Using Arduino / General Electronics / Re: continuous servo refuses to rotate any other direction on: September 02, 2011, 11:27:52 am
I have a usb breakoutboard from sparkfun that powers and serially connects my arduino to the computer. Then I have an external power src of 5v running in my servo. My servo has black, red and white wires so I naturally connect black to ground, red to power and white to arduino. though red is in between black and white, unlike in your diagram.

One thing though is that my servo does not share ground with the arduino, is that a big problem?
Pages: [1] 2