Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / error: conversion from 'PString' to non-scalar type 'String' requested on: August 08, 2012, 04:55:59 pm
I'm getting the error in the subject when trying to pass a string generated by PString to a function.  Can some knowledgeable person tell me what do I need to do to resolve this? 

Thanks in advance...

Code:
void loop() {

  if (client.isConnected()) {
    Serial.println("Old connection active. Closing");
    client.close();
  }

  PString postData(buffer, sizeof(buffer));
  postData.print("1,");
  postData.print(millis());

  Serial.print(postData);
  Serial.print(" - ");

  cosm(postData);

  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.isConnected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.close();
//    for(;;)
//      ;
  }

  delay(5000);
}


boolean cosm(String data){
  if (client.open("api.pachube.com", 80)) {
    Serial.println("connected to cosm...");
    for (int i=0;i<(sizeof(cosm_table)/sizeof(int));i++){   
      client.println(strcpy_P(buffer, (char*)pgm_read_word(&(cosm_table[i]))));
    }

    client.print("Content-Length: ");
    client.println(data.length());
    client.println();
    client.println(data);
    client.println();
  }
  else {
    Serial.println("connection to cosm failed.");
  }
}
2  Using Arduino / Programming Questions / How do I alias/instantiate the Serial class? on: August 06, 2012, 12:25:36 pm
I'm trying to connect an RN-XV wifi module to a duemilenove.  I'm finding the software serial interface to be a bit unstable for anything over 9600.  I want to use the UART interface in normal operation but without rewriting all of my code.  The best solution might be to use an alias, but you can't instantiate/alias the Serial class the way you can SoftwareSerial.  I'm a hardware guy :/

How can I do something like the following?

Code:

#ifdef DEBUG
  #include <SoftwareSerial.h>
  SoftwareSerial wifiSerial(8,9);
  Serial debugSerial;
#else
  Serial wifiSerial;
#endif

void setup()
{
 
#ifdef DEBUG   
    char buf[32];

    debugSerial.begin(57600);
    debugSerial.println("Starting");
    debugSerial.print("Free memory: ");
    debugSerial.println(wifly.getFreeMemory(),DEC);
etc...
3  Development / Suggestions for the Arduino Project / SHIFT + Backspace should not act like Delete on: January 17, 2012, 12:49:24 pm
I have a habit of holding the shift key down while navigating occasionally.  When I do that and hit backspace, it acts like hitting the delete key, deleting in the opposite direction.  It would be great if this could be toggled on/off somehow.
4  Development / Other Software Development / IDE change - please add support for ADC6 and ADC7 ! (SMD Uno) on: December 22, 2011, 12:04:21 am
I am building a custom board based on the SMD Uno.

I like being able to use the Arduino IDE to code/debug with.

I noticed that the SMD version of the Uno has access to 2 extra ADC-capable pins but it doesn't use them. What would it take to modify the IDE code to recognize and use those pins as A6 and A7 as well as D20 & D21?  The Uno itself wouldn't be able to take advantage of this change, but it would sure help those of us using this as a base for custom designs.  I could use the extra inputs!
5  Using Arduino / Programming Questions / Re: Creating comma delimited lists from integer values on: October 15, 2011, 01:38:18 pm
I should probably also mention that I could use some help parsing the comma delimited lists back out on the other side smiley
6  Using Arduino / Programming Questions / Testing for the existence of a sensor on: October 15, 2011, 01:28:03 pm
I'm trying to use an ee892 CO2 sensor in a project I'm working on.  It uses a proprietary low speed derivative of I2C but it's not compatible with the I2C bus.  Can you give me some ideas on how I could test to see if this thing is alive?

How do I strobe a pin to send a bunch of data then wait for a certain period for a reply before moving on?  It's the waiting for the reply part that I'm having problems with.
7  Using Arduino / Programming Questions / Creating comma delimited lists from integer values on: October 15, 2011, 01:24:49 pm
I have a bunch of sensors attached to an arduino and I want to assemble their values into a comma delimited list, similar to the javascript array.toString() function.  I'm assuming that will end up as a properly terminated char array.  If that's the case, how could I then get the length of the string dynamically? 

I'm trying to send the values to another devices using the RFM12b modules which require a buffer length.  Depending on the situation, there may be more or less sensors attached.  I want to test for their existence then include their values in the list only if they are there so I don't necessarily know what the buffer size is going to be before I start.

I'm new to C.  Thanks for your patience and willingness to help.
8  Forum 2005-2010 (read only) / Troubleshooting / Re: How do I install 3rd party libraries in Ubuntu? on: March 08, 2010, 05:55:22 pm
Perfect.  That's what I was both looking and hoping for smiley-wink
9  Forum 2005-2010 (read only) / Troubleshooting / How do I install 3rd party libraries in Ubuntu? on: March 08, 2010, 11:38:44 am
I'm on the current version of Ubuntu and managed to get the IDE and ftdi drivers installed.  But, when you use apt-get to install Arduino, it installs it in a locked folder into which I cannot copy files.  How do I add my 3rd party libraries?  (wishield, sensiron, rtc, etc)
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I pass an array to a function? on: June 24, 2010, 10:18:04 am
Yes.  My question is how does that work?  int and char are 2 different things.  I would expect an int array to hold only integer values, not characters like in my example:

Quote
int horserace_notes[] = {
  C4,F4,A4,C5,C5,C5,C5,0,A4,A4,A4,A4,0,F4,A4,F4,C4};
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I pass an array to a function? on: June 24, 2010, 05:36:36 am
That makes perfect sense!  It works now.  Thank you very much.

Would you mind explaining how I can put characters into an int array now?  That still seems very strange to me.
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I pass an array to a function? on: June 23, 2010, 08:10:50 pm
Thanks much for the help.  I've tried a few different options and none of them seem to work.  I think the problem is the int array holding char data but I don't know for sure.  I don't understand how that worked in the first place so it's hard to troubleshoot.  If anyone has any specific advice for this situation I would appreciate it greatly!
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: How do I pass an array to a function? on: June 23, 2010, 05:32:49 pm
The exact text:

Quote
Pointers are one of the more complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and and knowledge of manipulating pointers is handy to have in one's toolkit.

How do I use them?

I'm sorry, I've already searched the forums and google to try to resolve this myself.  I wouldn't be posting here otherwise.
14  Forum 2005-2010 (read only) / Syntax & Programs / How do I pass an array to a function? on: June 23, 2010, 04:17:09 pm
I'm hacking the melody example from here:  http://arduino.cc/en/Tutorial/Tone

I am trying to play several different melodies so I want to pass them to a function to play.  The arrays are showing up with len = 2 inside the playTune function.  I'm a javascript programmer so I'm sure this is a C++ syntax issue, especially since I don't understand how you can have an int array full of char data.

Thanks in advance for sharing your wisdom.

Quote
#include "pitches.h"

int speakerPin = 12;
int baseSpeed = 600;

int horserace_notes[] = {
  C4,F4,A4,C5,C5,C5,C5,0,A4,A4,A4,A4,0,F4,A4,F4,C4};
int horserace_beats[] = {
  4, 4, 4, 4, 8, 8, 8, 8, 4, 8,8, 8, 8, 4, 4, 4, 2 };


void setup() {
  Serial.begin(9600);

  playTune(horserace_notes,horserace_beats);
}

void loop() {
  // no need to repeat the melody.
}


void playTune(int notes[], int beats[]) {

  int len = sizeof(beats)/ sizeof(int);
  Serial.print(sizeof(beats));

  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < len; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = baseSpeed/beats[thisNote];
    tone(12, notes[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
  }
}

15  Forum 2005-2010 (read only) / Syntax & Programs / textString/WString hangs my Arduino? on: April 01, 2009, 05:12:37 pm
I replaced some low level char-array code with textString http://www.arduino.cc/en/Tutorial/TextString today after some frustration trying to get a time string formatted.  Now my arduino hangs after looping several times.  I suspect a buffer overflow or that I'm exceeding my available RAM but I don't know enough about this stuff to know.

Forgive me for pasting the entire code block - it's a little trashed from troubleshooting.  Since the problem could be somewhere other than the string handling, though...

This is code for a lap counter.  There is a PIR attached to the sensor pin.  On every lap I'm printing the lap number and last lap time to a sparkfun LCD.  There are also the requisite blinkenlights.  It used to count to 120+ now it only goes to 10 before hanging or resetting.

Code:
#include <SoftwareSerial.h>
#include <WString.h>

#define rxPin 2
#define txPin 3
#define LCDdelay 75
#define blinkDelay 150
#define warmup 8
#define lastlap 49

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

unsigned long time = 0;         // the last time the output pin was toggled
long debounce = 8000;

long loopCount = 0;
long lastLapTime = 0;

int sensorPin = 8;
int switchPin = 9;
int redPin = 13;
int ylwPin = 12;
int grnPin = 11;
int buzPin = 10;

String pBuffer = "";

char message[17];
int i = 0;
char lastMessage[17];
char b[2];

void setup()
{
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);  
  Serial.begin(9600);

  pinMode(sensorPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(ylwPin, OUTPUT);
  pinMode(grnPin, OUTPUT);
  pinMode(buzPin, OUTPUT);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  backlightOn();
  delay(500);
  sPrint("CountBot v1.1");
  sPrint("Sporks R Us Ltd.");
  delay(1500);
  clearLCD();
  sPrint("Warming up PIR..");
  
  for (i=warmup;i>=0;i--){
    delay(1000);
    pBuffer.append(i);
    sPrint(pBuffer.append("..."));
  }
  
  delay(1000);
  clearLCD();
  sPrint("Ready!");
  
  time = millis();

}

void loop()                     // run over and over again
{
  reading = digitalRead(sensorPin);
  
  //digitalWrite(grnPin, reading);
  
  // if we just pressed the button (i.e. the input went from LOW to HIGH),
  // and we've waited long enough since the last press to ignore any noise...  
  if (reading == LOW && previous == HIGH && millis() - time > debounce) {
    
    // ... invert the output

    state = !state;
    
    lastLapTime = millis() - time;
    
    time = millis();  // ... and remember when the last button press was
    
    loopCount++;
    
    // Serial.println(timeFormat(lastLapTime));
    printLap(loopCount,lastLapTime);
    
    blinkLED(buzPin,1);
  }

  if (loopCount >= lastlap){
     blinkLED(redPin,2);
     blinkLED(ylwPin,2);
     blinkLED(grnPin,2);
  }

  previous = reading;
  
}

void printLap(int lap, long lapTime){
    String buffer = "# ";
  
    // pBuffer.append(loopCount<10 ? "0" : "");
    buffer.append(lap);
   // pBuffer.append(" LL: ");
   // pBuffer.append(timeFormat(lastLapTime));
    sPrint(buffer);
}

/*********************************************************
 *
 * General functions
 *
 **********************************************************/

void blinkLED(int targetPin, int numBlinks) {
  // this function blinks the status LED light as many times as requested
  for (int i=0; i<numBlinks; i++) {
    digitalWrite(targetPin, HIGH);   // sets the LED on
    delay(blinkDelay);                     // waits for a second
    digitalWrite(targetPin, LOW);    // sets the LED off
    delay(blinkDelay);
  }
}

String timeFormat(long inTime){
    inTime = inTime / 1000;
    
    String output = "";
    int seconds = (int)(inTime % 60);
    int minutes = (int)((inTime/60) % 60);
    int hours = (int)((inTime/3600) % 24);
    output.append(minutes<10 ? "0" : "");
    output.append(minutes);
    output.append(":");
    output.append(seconds<10 ? "0" : "");
    output.append(seconds);
    return output;
 }




/*********************************************************
 *
 * LCD functions
 *
 **********************************************************/
 
void sPrint(String localMessage) {
  clearLCD();
  delay(LCDdelay);
  selectLineOne();
  delay(LCDdelay);
  mySerial.print(lastMessage);    
  delay(LCDdelay);
  selectLineTwo();
  delay(LCDdelay);
  mySerial.print(localMessage);
  strcpy(lastMessage,localMessage);
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
  if (position<16){
    mySerial.print(0xFE, BYTE);   //command flag
    mySerial.print((position+128), BYTE);    //position
  }
  else if (position<32){
    mySerial.print(0xFE, BYTE);   //command flag
    mySerial.print((position+48+128), BYTE);    //position
  }
  else {
    goTo(0);
  }
}

void clearLCD(){
  mySerial.print(0xFE, BYTE);   //command flag
  mySerial.print(0x01, BYTE);   //clear command.
  delay(LCDdelay);
}
void backlightOn(){  //turns on the backlight
  mySerial.print(0x7C, BYTE);   //command flag for backlight stuff
  mySerial.print(157, BYTE);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  mySerial.print(0x7C, BYTE);   //command flag for backlight stuff
  mySerial.print(128, BYTE);     //light level for off.
  delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands  
  mySerial.print(0xFE, BYTE);
  delay(LCDdelay);
}



Pages: [1] 2