Show Posts
Pages: [1] 2 3 ... 18
1  Using Arduino / Programming Questions / Re: Switch and Case question on: April 16, 2014, 10:08:46 pm
I am not sure if I can get live readings in a switch/case statement, however I can't stop my robot if I can't read these potentiometers.

Why not?  And why not just put your robot "up on blocks" while you test the code?

BTW... your code contains the following construct:

        while (val0 >500)
          Serial.print ("value = ");
          Serial.println (val0);

Hint:  Inside of a while loop it is normal to check the condition that is keeping you in the loop to see if anything has changed.  As written, if you do get inside that while loop you'll never get back out.

Also can you really do the following?   Outside of any function?  Does each (poorly named) int just get zero'd?

int val0 = analogRead(0);
int val1 = analogRead(1);
int val2 = analogRead(2);
int val3 = analogRead(3);
int val4 = analogRead(4);

But overall it'd really help with debugging your code if you could include the serial debug information.  That's the easiest way to see what's going on.



PS rglazebr's suggestion is a good one... if nothing else it's bad style
2  Using Arduino / Programming Questions / Re: GPS with Arduino UNO - 2. on: April 16, 2014, 09:22:57 pm
One thing that helps when troubleshooting GPS issues is to skip the Arduino and connect your GPS directly to your PC (typically you'll need a TTL Serial to USB adapter.  If you don't have one, you should get one).

You can then use SirfDemo directly from a Windows PC (see

Worst case that thread has the exact commands you need to reset your GPS and to switch to NMEA mode.  Combine that with the software from the DIY Drones link I posted earlier should give you everything you need to reset your GPS.

Does that help?


3  Using Arduino / Programming Questions / Re: UNO & GY-GPS6MV2 on: April 16, 2014, 07:05:24 pm
Is this GPS working INDOORS ?

It might be.  Ublox makes a pretty decent GPS.  I've never used the NEO-6 like the OP, but I've used MAX-6 and MAX-7's and have no problem getting a fix indoors, even with a lousy chip antenna (it might take me 10 minutes though ;-) ).

Any advice gratefully received

I like TinyGPS ( for parsing the output of a GPS if you don't mind using a library (though I suspect you are wanting to write your own parser?)



EDIT: Added comment about TinyGPS
4  Using Arduino / Programming Questions / Re: 1st code on: April 16, 2014, 06:53:44 pm
First of all , the IDE is not like a normal install program where you double click once and it starts a process that pops up windows
to which you just click "next" or "ok".  It's not like that at all. It's really nothing more than a bunch of files you unzip an put somewhere.

That does depend on what you install:  If you look at you'll see a full-blown Windows installer as well as the zip file you are talking about.


5  Using Arduino / Programming Questions / Re: integrating ublox max 7, Sensors (various), SD Card, andRadiometrix transmitter. on: April 16, 2014, 06:48:39 pm

So what are you trying to make?  Don't tell me it's an APRS tracker?  (isn't that what the HX1 is best for?)

A good example of a piece of code that integrates everything you want except the SD card (and maybe the sensors, not sure what you're looking for) is Trackuino.  See

Note it doesn't explicitly use a MAX-7, just a gps.  I've modified the Trackuino code to explicitly support a MAX-6 (which should be nearly identical to the MAX-7) if you're interested.

Just a thought.


6  Using Arduino / Programming Questions / Re: Understanding state machine example on: April 16, 2014, 06:36:45 pm
Thanks for the catch on that.  I've changed them to long.

It would be better to change them to be:

const int StartTime = 500;
const int ScanTime = 1500;
const int RESULTSTime = 1500;
const int ResetTime = 2000;

Since they won't ever change (hence the 'const' keyword) and they are much smaller than a long you can save some memory by keeping them ints.


7  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 15, 2014, 10:03:56 pm
also make sure that the getRecievedValue() function has a return type of unsigned long as well.


That was supposed to be the point of my poorly edited post (done via tablet at McDonalds on break).

In the library being used the getReceivedValue() function does indeed have a return value of unsigned long, which is what I was trying to indicate.

Thanks for making a much clearer post than I did.


8  Using Arduino / Programming Questions / Re: Having trouble "inserting" new characters to a String object. on: April 15, 2014, 09:33:35 pm
The function-local dMessage is wiped out when the function ends, it has gone out of scope. So when the code gets the return (an address to the object) the object is gone.

Thanks for the clarification.  That sounds like nikosk's problem (Strings not withstanding).  Guess I was confused.


9  Using Arduino / Programming Questions / Re: GPS with Arduino UNO - 2. on: April 15, 2014, 07:13:27 pm
So, what should I do to make sure that my GPS is in the NMEA mode ?!!.

Looks like has some example code that might help.

BTW you're not using the 1.5.x beta IDE are you?  When I've used 1.5.6 with my 328 and the serial port I noticed I had to reset my Arduino a couple of times and open/close the serial monitor to get it to properly change baud rates.

Maybe a problem on my end but if you're using the beta you might want to try 1.0.5.

Hope this helps,

10  Using Arduino / Programming Questions / Re: Having trouble "inserting" new characters to a String object. on: April 15, 2014, 06:38:20 pm
Not sure what you're trying to say Brad. I'm not at that level of commanding English language and definitely nowhere near newbe level when it comes to C/C++.

Well take a look at and "Trap #18".

I just wanted to clarify that your code avoids that problem because you're using a String and not a character array.

BTW, when you use the strcat function you need to use two strings, otherwise you risk corrupting memory (your posted code tries to append a single char to an array which is bad because it will keep copying until it gets the terminating null).


11  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 15, 2014, 03:58:32 pm
Check the return value from getReceivedValue, it's supposed to be an unsigned long.

That's why 6 digits doesn't work (you're overflowing your unsigned int).

Hope this helps,


EDIT: Minor typo/grammar correction/ugh!
12  Using Arduino / Programming Questions / Re: Parsing a part of a string of unknown length on: April 15, 2014, 03:01:23 pm
Personally I'm with jasit... it's easier to simply search for the colon because then you can easily find the column name and the contents of the column all by searching for one character.

An example (to just fetch the data not the column information) would look something like:

char * parseCommand(const char * toParse, const char toFind, char  *results) {
  char * spot = strchr(toParse, toFind);
  results[0]  = '\0';
  if (spot != NULL) {
    // Warning: Make sure that 'results' is large enough to hold the string
    return strcpy(results, &toParse[spot - toParse + 2]);
    return NULL;


 parseCommand("AVRCP_MEDIA TITLE: Captain", ':', name);
 parseCommand("AVRCP_MEDIA ARTIST: Dave Matthews Band", ':', artist);
 parseCommand("AVRCP_MEDIA ALBUM: Busted Stuff", ':',  album);
 parseCommand("AVRCP_MEDIA NUMBER: 337", ':', mediaNo);
 parseCommand("AVRCP_MEDIA TOTAL_NUMBER: 498", ':', totalNo);
 parseCommand("AVRCP_MEDIA GENRE: Rock", ':', genre);

Not really a very good example of usage but I hope you get the idea.


13  Using Arduino / Programming Questions / Re: Having trouble "inserting" new characters to a String object. on: April 15, 2014, 02:36:00 pm
This is outside of the question but I'm curious.  If you strip the OP's code down a bit you get the following:

String decodeMessage (String eMessage, int messageLenght) {   
String dMessage;


return dMessage;

Now if decodeMessage was using a character array I'd say this code is less than desirable because you shouldn't return a reference to a local variable (instead you pass the array by reference as an argument).

So is this ok? Because it's using an object?  (my mind seems to recall something about objects being returned by value)

Just curious.


14  Using Arduino / Programming Questions / Re: Example: SerialBlinkWithoutDelay on: April 13, 2014, 10:40:19 pm
You might get out of sync with the time, since you use millis() twice.

Possibly, yes, but won't that take quite a long time?  If the application is that time sensitive perhaps the example should be more like this?

// Constants
const byte MAX_STRING_LEN = 40;
const byte LED_PIN        = 13;
const int  BLINK_INTERVAL = 1000;

// Variables
char inputString[MAX_STRING_LEN];  // a string to hold incoming data
unsigned long previousMillis = 0;  // Last time we blinked
byte ledState = LOW;               // Current state of LED (HIGH=On)
byte strLen   = 0;                 // current length of rec'd string

void setup() {
  Serial.begin(19200);             // Change baud rate to suit
  pinMode(LED_PIN, OUTPUT);

void loop() {
  // Check the serial port for any pending data
  if (processSerial()) {
    // Received a complete string. For now, just echo it back

    // Finally setup for the next string
    inputString[0] = '\0';         // Make sure array is empty
    strLen         = 0;            // reset length to zero

  // Here is where you do the processing that needs to be done each
  // pass thru the loop (such as checking to see if it's time to blink)
  unsigned long now = millis();
  if(now - previousMillis > BLINK_INTERVAL) {
    // save the last time you blinked the LED
    previousMillis = now;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
      ledState = LOW;

    // set the LED with the ledState of the variable
    digitalWrite(LED_PIN, ledState);

// Check the Serial port and gather any pending data
boolean processSerial() {
  while (Serial.available()) {
    char inChar = (char);

    // We are done receiving the string if we received a return (or line feed)
    if ((inChar == '\n') || (inChar == '\r')) {
      return true;

    // add it to the inputString if we have room
    if (strLen < (MAX_STRING_LEN - 1)) {
      inputString[strLen++] = inChar;
      inputString[strLen]   = '\0';

  return false;
15  Using Arduino / Programming Questions / Re: Data Logging Stops After Losing GPS Signal on: April 13, 2014, 10:34:53 pm
Well, the example was actually one of the examples given by the author of the TinyGPS++ library, so I assume that something about the isUpdated function works with the gps.location (or speed, or date) object and only checks that portion of the string? But it actually seems to work fine.

You're right, my apologies.  Of course you first see the examples 'BasicExample.ino' and 'DeviceExample.ino'  - each written as I suggested - before you come to 'KitchenSink.ino' that uses the same if/else if structure you do.

I'll point to BlinkWithoutDelay and say just because an example does it one way doesn't mean it's correct.  I still think the logic of only updating the time if the location and speed are constant is a mistake.

But if it works for you who am I to argue?


Pages: [1] 2 3 ... 18