Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / String comparison troubles on: March 24, 2014, 10:41:54 am
Hi,
I'm not very educated in arduino code, kinda on a "copy, paste and modify"-level, so I guess my question here is also what I should read up on, or good strategies for testing.

I got a CC3000 wifi shield from Adafruit nicely connecting and displaying the values I send to it (SR1 + numbers) but when I try to use an if function (  if ((String)command == "SR1")) to determine what message is coming in it does not react to it at all. Am I converting from char to String properly?

Any input is highly appreciated smiley

Code:
void loop()
{
  // initialization of the variables
  char command[3];      // commandstring
  unsigned int vnumber; // the value as integer
  boolean flag = true;  // a flag to seperate the command from the value
  
  Serial.println("I'm in grabInput");
  
//------check client socket open----//
    if(client.connected()) {
      Serial.print(F("connected to UDP port  "));
      Serial.println(port);
    }
//-------end of socketcheck------//

  int inData;
  Serial.print("inData start value = ");Serial.println(inData);
  sockLen = sizeof(sockaddr_in);
 Serial.println("receive test ...");
 inData = recvfrom(sockfd, buff, sizeof(buff), 0, (sockaddr*)&from, &sockLen);
  
 //-----collect buffer contents------//
  value = "";
  for(int i=0;i<sizeof(buff);i++){
      if (i < 3)  // the first 3 characters
      {
      command[i]=buff[i];
      }
      else        // the last characters are the value
      {
        value += (char)buff[i];
      }
    }
    
    value += "\0";      // necessary - the string ends here
    command[3] = '\0';
    vnumber = value.toInt();  // string to integer
    

// SEND THE COMMANDS TO THE SERVOS
    if ((String)command == "SR1")
    {
      Serial.println("writing to SR1");
      Servo1.write(vnumber);
    }
 
   if(inData > 0){
     Serial.println("in");}
       else { Serial.println("nothing received");
       }
    //delay(10);
 }
2  Using Arduino / Audio / Re: Seeed Music Audio Shield on: January 14, 2013, 10:31:46 am
Hi there,

I'd be interested to know which libraries and code you used to make it work just to play mp3's, and on what arduino board. Did you have any other problems?

best,
g
3  Using Arduino / Sensors / Re: N00b: pausing a loop on: November 16, 2012, 10:31:38 am
Hi,

thanks for the tip. I understand the concept, but I still get the same result, the light blinking at the interval.

And even stranger to me, is the output printed, this is without touching the switch at all:
(first int is the previous value of 'val', second is 'val' as gotten fresh from the digital input, third is the updated 'previousVal' as 'val')

Ready
1
0
0
writing HIGH
0
1
1
writing LOW
1
0
0
writing HIGH
0
1
1
writing LOW
1
0
0
writing HIGH
0
1
1
writing LOW
1
0
0
writing HIGH
0
1
1
writing LOW
1
0
0
writing HIGH
0
1
1
writing LOW
1
0
0
..... and so on.


Heres my updated code:


Code:

#include <Servo.h>
Servo servoMain; // Define our Servo


int ledPin = 13; // choose the pin for the LED
int inPin = 9;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int previousVal= 1;

long previousMillis = 0;        // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 2000;           // interval at which to blink (milliseconds)

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
 
  servoMain.attach(5); // servo on digital pin 5
  Serial.begin(9600);    //Start Serial Communications with PC
  Serial.println("Ready");
}

void loop(){
 
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
 
    val = digitalRead(inPin);  // read input value
   
    if (val != previousVal) {
      Serial.println(previousVal);
      Serial.println(val);
      previousVal= val;
      Serial.println(previousVal);
     
    if (val == LOW) {         // check if the input is HIGH (button released)
      digitalWrite(ledPin, HIGH);  // turn LED OFF
      // Run Servo
      //servoMain.write(45);
      Serial.println("writing HIGH");
      previousMillis = currentMillis;

    } else {
      digitalWrite(ledPin, LOW);  // turn LED ON

      // Run Servo
      //servoMain.write(0);
      Serial.println("writing LOW");
     
   
    }
    }
  }
}
4  Using Arduino / Sensors / N00b: pausing a loop on: November 15, 2012, 03:39:55 pm
Hi all,

I'm quite fresh with arduino, and haven't seen a tutorial covering this.

I'm trying to make a switch trigger a servo in the way that it would move it (and turn on the LED at pin 13) and then ignore if the switch turns on or off for a certain amount of time, here 2 seconds.

I thought I would achieve this by inserting a delay(2000) after it reads the pin as being HIGH, but this results in the LED at pin 13 blinking at a 2 second interval.

Any hints are greatly appreciated!

In the end I would like to make the switch trigger a soundfile on the seeduino music shield, and ignore any switch changes until the soundfile has finished...

Code:

#include <Servo.h>
Servo servoMain; // Define our Servo


int ledPin = 13; // choose the pin for the LED
int inPin = 8;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int reset= 0; // var to not send out to many messages to servo

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
 
  servoMain.attach(5); // servo on digital pin 5
  Serial.println("Ready");
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
    // Run Servo
    servoMain.write(45);
    delay(2000);
    reset= 0;

  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (reset == 0)
    {
    // Run Servo
    servoMain.write(0);
    }
    reset= 1;
   
   
  }
}
5  Forum 2005-2010 (read only) / Interfacing / Re: Can somebody test my new Trackpad library? on: September 18, 2010, 09:35:58 am
Hi,
now I'm trying to expand to using two touchpads, but I'm having a problem differentiating between the values of the two. I made a try in the code below but SuperCollider, which Im using to interpret the values, is sometimes mixing them up. By dumping "first" and "second" before the values from the respective touchpad I route the coming values in SuperCollider to control two different objects..

What would be ideal is to be able to send a DUMP with a different name than "packet->x", like "packet->x2" (or a name I write) for the second touchpad, then I can easily grab it in SuperCollider.

so, this is how my loop{} looks now:
Code:

void loop()
{
      static packet_t oldPacket;
      static packet_t oldPacket2;
      packet_t * packet;
      packet = t.getNewPacket();

      if(!packetsEqual(&oldPacket, packet)) {
            DUMP("first");
            DUMP(packet->x);
            DUMP(packet->y);
            //DUMP(packet->z);
            //DUMP(packet->w);
            DUMP(packet->leftButtonDown);
            DUMP(packet->rightButtonDown);

            Serial.print("\n");
#if ANSI_TERMINAL
            Serial.print(0x1B,BYTE);
            Serial.print("[H");
#endif
            Serial.print("\n");
            // copy the current packet
            oldPacket = *packet;
      }

      packet = t2.getNewPacket();

      if(!packetsEqual(&oldPacket2, packet)) {
                DUMP("second");
            DUMP(packet->x);
            DUMP(packet->y);
            //DUMP(packet->z);
            //DUMP(packet->w);
            DUMP(packet->leftButtonDown);
            DUMP(packet->rightButtonDown);

            Serial.print("\n");
#if ANSI_TERMINAL
            Serial.print(0x1B,BYTE);
            Serial.print("[H");
#endif
            Serial.print("\n");
            // copy the current packet
            oldPacket2 = *packet;
      }
}

cheers!
g
6  Forum 2005-2010 (read only) / Interfacing / Re: Can somebody test my new Trackpad library? on: September 09, 2010, 06:36:33 am
Hi Joe, just to say that it worked fine! This saves a lot of cpu on my pc.

Next step for me is to find an other touchpad. I got one really cheap off ebay and its really overly sensitive. I can have my finger 0.5cm over it and it still gets a signal somehow.

Thanks! smiley
7  Forum 2005-2010 (read only) / Interfacing / Re: Can somebody test my new Trackpad library? on: August 19, 2010, 08:58:53 am
Thank you Joe!! Im heading off to the mountains to do some work without internet now so I'll tell you how its come out in a weeks time.

cheers!
g
8  Forum 2005-2010 (read only) / Interfacing / Re: Can somebody test my new Trackpad library? on: August 19, 2010, 05:55:13 am
Thank you! Worked just like that, and I have never really gotten my fingers into C or C++ or whatever code that was before smiley-grin

I put the modified library on the wiki (http://www.arduino.cc/playground/Main/Trackpad) as I cant find a way to attach it here.

I have another question, please excuse me if its a bit of a noob question not specific to your lib. How can I make the code in Trackpad_print.pde only send out values when they change? There are probably standards for doing this so I only need where to look for answers maybe.

again, thanks for the nice lib!
g
9  Forum 2005-2010 (read only) / Interfacing / Re: Can somebody test my new Trackpad library? on: August 17, 2010, 06:22:54 am
Hi,

It works here with my 135227-001 Synaptic trackpad!
This was great for me since I needed absolute position readings.

however, Im getting the x, y, z, w readings, but how do I read the buttons?

cheers!
gorgon
10  Forum 2005-2010 (read only) / Interfacing / Re: reading CV  from volume pedal on: November 28, 2008, 04:57:35 pm
Quote
tip = 5v (from arduino)
ring = analog pin

this does also not work, it only gives the value 0.
11  Forum 2005-2010 (read only) / Interfacing / Re: reading CV  from volume pedal on: November 28, 2008, 02:55:28 pm
thanks for the quick reply MikMo.

so,
tip -> analog in
ring -> ground

does not give me anything. I doubt that the pedal sends out any voltage.
12  Forum 2005-2010 (read only) / Interfacing / reading CV  from volume pedal on: November 28, 2008, 12:41:16 pm
Hi!

Does anyone know how to read CV (control voltage) from a expression/volume pedal (ex behringer fcv100)? Connecting a jack cable to the output of the pedal and then the tip to analog in and the ring to 3/5v on the arduino gives no result.

This is what the specs sheet on the pedal says:
input/output:
1/4" TS connectors, unbalanced
Tip: Supply voltage from unit/instrument
to be controlled (Impedance: 50 k[ch937])
Ring: Slider pick-up (control voltage
dependend on pedal position
(Impedance: 0...50 k[ch937])

Sorry if this is very basic - I couldnt find any info on it when searching.. Any help is highly appreciated!

Thanks!
Martin
13  Forum 2005-2010 (read only) / Exhibition / Re: Touchpad Midi on: August 18, 2010, 03:45:24 pm
@antima55:
the wiring is different on more or less every touchpad. I had to experiment for about 40min to find the right one for my touchpad 135227-001, which btw is:
black= 5v
orange= gnd
red= 6
brown= 5
(it searched for it and it gave no answers)

good luck! its not at all tricky, just takes some time smiley
Pages: [1]