Pages: 1 ... 9 10 [11]   Go Down
Author Topic: NewSoftSerial Library: An AFSoftSerial update  (Read 17313 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Eoo, Great hint, that was it!
Now it works.
Thanks a lot, Groove.

There's another thing i can't explain myself: After uploading the code on to the arduino, i use the first tag and the LED shows me that it reads it, but in the serial window nothing appears (it should write the tag number and a string with the tagname). The next tag i give him to read (or the same tag again) it reads and writes now as it should without problems. I tried that out several times and i reloaded the code as well, but it's always the same.
And when i open up the serial monitor the monitor bar below says "closing..."

What might that be?
« Last Edit: May 13, 2010, 05:41:16 pm by flofluse » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Lee:

I'm very interested in your entirely interrupt-driven serial port. I had also had this idea, but was too daunted to implement it myself.

Have you developed it any further? Have you come across particular problems, or know perhaps where the threshold of compromise appears, when the increased interrupts start to consume as much resources as the polling of the original NewSoftSerial?

Thanks most kindly,
Robert.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

very good post, thanks ..........
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently purchased a cellular shield with SM5100B GPRS module from sparkfun. I then downloaded the sketch "cellular shield throughpass" from the sparkfun website, my problem is that when I try to compile it I get a error.

Because "Newsoftserial" is not included in my import library, I've being using "#include <SoftwareSerial.h> at the beginning of the sketch instead, i then get a " error 'newsoftserial' does not name a type".

Any help on this would be much appreciated,
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50366
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because "Newsoftserial" is not included in my import library,
So, download it. http://arduiniana.org/libraries/NewSoftSerial/

Quote
I've being using "#include <SoftwareSerial.h> at the beginning of the sketch instead,
How is that supposed to help?

Quote
i then get a " error 'newsoftserial' does not name a type".
Well, NewSoftSerial would name a type, if you included the proper header file.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to create a solution to allow gauges to send data to a PC or handheld device wirelessly.

NewSoftSerial has been great to allow me to put my XBee module to sleep, and wake it upon receiving data from a gauge. (Very important for battery life)

I have it working with basic serial (Tx, Rx, Grnd).
However, I have a device that needs RTS, CTS support. I have since had to purchase a shifter that uses the MAX232 board so I can have access to those lines.

I'm using the Arduino FIO board. Below are the pins I'm using, and what I'm using them for.

D2 = Rx (Gauge Rx)
D3 = Tx (Gauge Tx)
D4 = CTS (XBee CTS)
D5 = DTR (XBee DTR)
D6 = RTS (Gauge RTS)
D7 = CTS (Gauge CTS)

The particular gauge I'm trying to connect to is the Tohnichi CTB2 using their PC output.

It seems they actually route their "RTS" to the CD (Pin 1 of a DE9), and CTS gets Pigtailed into the Pin 7 and 8 of the DE9. I have a modified cable that is wired just the way they had their RS232 cable wired. I can post some excel files once I'm allowed to do so that will show the pin outs and cabling I'm using. I'm thinking I may need to re-wire my cable, but I'm not positive at this point. I also know that NewSoftSerial doesn't support RTS/CTS.

I finally found Jin's code where he had some RTS/CTS stuff in with a TimerSerial setup. I'm not sure how to adapt that to be used with the latest NewSoftSerial. I would be more than happy to make those changes myself, but I don't know what they are, and I would like some ideas on the direction to take for the cable. I did put the RTS and CTS lines to their correct locations and I'm getting a CTS: High, and RTS: Low while it's just sitting there. I don't seem to see those change. Even when I try to send data from the wrench. :-/

Also here's my sketch. I can't post code in my first post?

Obviously I have some code in there checking those pins. However, they both are coming in as the same thing, and never change except when I change them. Though I just tested with having changed the cable, and I'm getting values as described above, but still nothing changing when I send data FROM the wrench TO the Arduino FIO.

Thanks for ANY and ALL suggestions!! I'm trying to get this done in the next day or two.

Thanks,
Jarvis
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the code portion of the above post since I couldn't post it.

Code:
/*
Arduino FIO + XBee Radio + RS-232 Breakout (DB9 Female)
Created this to allow the XBee radio to sleep. Gauges can't
wake the module. The FIO board wakes the radio.

Below are the steps this sketch should take to work properly

1. When serial data is recieved. Hold the Data
2. Wake up the XBee Radio (Set DTR(PN D5) HIGH)
3. Wait for XBee to signal it's ready. (Check CTS(PN D4) LOW)
4. Wait a few mili seconds.
5. Send received serial data through XBee

Added RTS/CTS support through setting the pins high and low.

Created by: Jarvis J Stubblefield
Created on: 2010/11/05
Updated on: 2010/11/12
*/

#include <NewSoftSerial.h>
#include <avr/power.h>
#include <avr/sleep.h>

//Pin CONSTANTS
const byte pinRx   = 2;
const byte pinTx   = 3;
const byte pinCTS  = 4;
const byte pinDTR  = 5;
const byte pinGRTS = 6;
const byte pinGCTS = 7;

//String for Serial Data
String strData;

//Counter for Auto-Sleep
int intCounter;

//Soft Serial for Storing Data
NewSoftSerial objGauge(pinRx, pinTx); //This function takes care of setting pinMode

void setup() {
  pinMode(pinGRTS, INPUT);
  digitalWrite(pinGRTS, LOW);
  pinMode(pinGCTS, OUTPUT);
  digitalWrite(pinGCTS, HIGH);
  pinMode(pinDTR, OUTPUT); //Set DTR to be an OUTPUT pin
  digitalWrite(pinDTR, HIGH); //Set pin to HIGH so we can wake with LOW
  digitalWrite(pinCTS, HIGH); //Set pin to HIGH so we can later wake and check for LOW
  Serial.begin(9600);
  Serial.println("Setup almost done.");
  objGauge.begin(9600);
  intCounter = 0;
}

void loop() {
  if (digitalRead(pinGRTS) == HIGH) {
    Serial.println("RTS: HIGH");
  }
  else if (digitalRead(pinGRTS) == LOW) {
    Serial.println("RTS: LOW");
    digitalWrite(pinGRTS, HIGH);
  }
  if (digitalRead(pinGCTS) == HIGH) {
    Serial.println("CTS: HIGH");
  }
  else if (digitalRead(pinGCTS) == LOW) {
    Serial.println("CTS: LOW");
    digitalWrite(pinGCTS, HIGH);
  }
  
  if (objGauge.available())
  {
    char chrIncoming;
    
    //Serial Data is coming in. Wake up the XBee.
    if (digitalRead(pinDTR) == HIGH) {
      digitalWrite(pinDTR, LOW);
    }
    
    //Read in the characters until you have a full string.
    while (objGauge.available()) {
      chrIncoming = (char)objGauge.read();
      strData += chrIncoming;
      // If you find a LFCR or CRLF then you have a full reading.
      if (strData.endsWith("\n\r") || strData.endsWith("\r\n")){
        break;
      }
    }
    
    delay(50); //Delay to wait for XBee to wake.
    //Check for the radio to be awake (CTS = LOW)
    if (digitalRead(pinCTS) == LOW) {
      if (strData.length() > 0) {
        Serial.print(strData);
        strData = ""; //Prepare for new data coming in.
        delay(50); //Wait a bit then sleep again.
        digitalWrite(pinDTR, HIGH);
        Serial.flush(); //Flush the serial stream.
        objGauge.flush(); //Flush the gauge stream.
      } //End strData has length
    } //End pinCTS == LOW
  } //End objGauge.available()
  delay(100); //Sleep a little between looping (ms)
  intCounter++;
  
  if (intCounter == 10)
  {
    intCounter = 0; //Reset counter
    //sleepNow();
  }
}

void sleepNow()
{
    /* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and
     * wake up sources are available in which sleep modus.
     *
     * In the avr/sleep.h file, the call names of these sleep modus are to be found:
     *
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_SAVE
     *     SLEEP_MODE_STANDBY
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     *
     *  the power reduction management <avr/power.h>  is described in
     *  http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
     */

  set_sleep_mode(SLEEP_MODE_IDLE);   // sleep mode is set here

  // enables the sleep bit in the mcucr register so sleep is possible. just a safety pin
  sleep_enable();

  //Turn OFF unused modules to pull even less power.
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  
  sleep_mode(); // here the device is actually put to sleep!!
 
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_disable(); // first thing after waking from sleep: disable sleep...

  power_all_enable(); // Turn EVERYTHING back on.
}

Thanks again for all help and suggestions,
Jarvis
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the code that I have now. It gives me a RTS: HIGH, CTS: HIGH only SOMETIMES when I press the send reading button on the gauge.

Mostly it stays like this...
Quote
RTS: LOW, CTS: LOW
RTS: LOW, CTS: HIGH
RTS: LOW, CTS: LOW
RTS: LOW, CTS: HIGH
RTS: LOW, CTS: LOW

Occasionally when I press the button, I get the following...
Quote
RTS: LOW, CTS: LOW
RTS: HIGH, CTS: HIGH
RTS: LOW, CTS: LOW
RTS: LOW, CTS: HIGH

I'm guessing this is because I probably need interrupts on the RTS/CTS not checking during my loop. I'm unsure how to get this implemented, but I'm looking at the TimerSerial by Jin to see if I can figure it out.

Here's my current code generating the above output.
Code:
/*
Arduino FIO + XBee Radio + RS-232 Breakout (DB9 Female)
Created this to allow the XBee radio to sleep. Gauges can't
wake the module. The FIO board wakes the radio.

Below are the steps this sketch should take to work properly

1. When serial data is recieved. Hold the Data
2. Wake up the XBee Radio (Set DTR(PN D5) HIGH)
3. Wait for XBee to signal it's ready. (Check CTS(PN D4) LOW)
4. Wait a few mili seconds.
5. Send received serial data through XBee

Added RTS/CTS support through setting the pins high and low.

Created by: Jarvis J Stubblefield
Created on: 2010/11/05
Updated on: 2010/11/12
*/

#include <NewSoftSerial.h>
#include <avr/power.h>
#include <avr/sleep.h>

//Pin CONSTANTS
const byte pinRx   = 2;
const byte pinTx   = 3;
const byte pinCTS  = 4;
const byte pinDTR  = 5;
const byte pinGRTS = 6;
const byte pinGCTS = 7;

//String for Serial Data
String strData;

//Counter for Auto-Sleep
int intCounter;

//Soft Serial for Storing Data
NewSoftSerial objGauge(pinRx, pinTx); //This function takes care of setting pinMode

void setup() {
  pinMode(pinGRTS, INPUT);
  digitalWrite(pinGRTS, LOW);
  pinMode(pinGCTS, OUTPUT);
  digitalWrite(pinGCTS, HIGH);
  pinMode(pinDTR, OUTPUT); //Set DTR to be an OUTPUT pin
  digitalWrite(pinDTR, HIGH); //Set pin to HIGH so we can wake with LOW
  digitalWrite(pinCTS, HIGH); //Set pin to HIGH so we can later wake and check for LOW
  Serial.begin(9600);
  Serial.println("Setup almost done.");
  objGauge.begin(9600);
  intCounter = 0;
}

void loop() {
  //Attempting to perform RTS/CTS to get a gauge reading.
  
  if (digitalRead(pinGRTS) == HIGH && digitalRead(pinGCTS) == LOW) {
    Serial.println("RTS: HIGH, CTS: LOW");
    digitalWrite(pinGRTS, LOW);
    digitalWrite(pinGCTS, HIGH);
  }
  else if (digitalRead(pinGRTS) == LOW && digitalRead(pinGCTS) == HIGH) {
    Serial.println("RTS: LOW, CTS: HIGH");
    digitalWrite(pinGRTS, HIGH);
    digitalWrite(pinGCTS, LOW);
  }
  if (digitalRead(pinGCTS) == HIGH && digitalRead(pinGRTS) == HIGH) {
    Serial.println("RTS: HIGH, CTS: HIGH");
    digitalWrite(pinGCTS, LOW);
    digitalWrite(pinGRTS, LOW);
  }
  else if (digitalRead(pinGCTS) == LOW && digitalRead(pinGRTS) == LOW) {
    Serial.println("RTS: LOW, CTS: LOW");
    digitalWrite(pinGCTS, HIGH);
    digitalWrite(pinGRTS, HIGH);
  }
  
  if (objGauge.available())
  {
    Serial.println("Gauge Available");
    char chrIncoming;
    
    //Serial Data is coming in. Wake up the XBee.
    if (digitalRead(pinDTR) == HIGH) {
      digitalWrite(pinDTR, LOW);
    }
    
    //Read in the characters until you have a full string.
    while (objGauge.available()) {
      chrIncoming = (char)objGauge.read();
      strData += chrIncoming;
      // If you find a LFCR or CRLF then you have a full reading.
      if (strData.endsWith("\n\r") || strData.endsWith("\r\n")){
        break;
      }
    }
    
    delay(50); //Delay to wait for XBee to wake.
    //Check for the radio to be awake (CTS = LOW)
    if (digitalRead(pinCTS) == LOW) {
      if (strData.length() > 0) {
        Serial.print(strData);
        strData = ""; //Prepare for new data coming in.
        delay(50); //Wait a bit then sleep again.
        digitalWrite(pinDTR, HIGH);
        Serial.flush(); //Flush the serial stream.
        objGauge.flush(); //Flush the gauge stream.
      } //End strData has length
    } //End pinCTS == LOW
  } //End objGauge.available()
  delay(100); //Sleep a little between looping (ms)
  intCounter++;
  
  if (intCounter == 10)
  {
    intCounter = 0; //Reset counter
    //sleepNow();
  }
}

void sleepNow()
{
    /* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and
     * wake up sources are available in which sleep modus.
     *
     * In the avr/sleep.h file, the call names of these sleep modus are to be found:
     *
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_SAVE
     *     SLEEP_MODE_STANDBY
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     *
     *  the power reduction management <avr/power.h>  is described in
     *  http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
     */

  set_sleep_mode(SLEEP_MODE_IDLE);   // sleep mode is set here

  // enables the sleep bit in the mcucr register so sleep is possible. just a safety pin
  sleep_enable();

  //Turn OFF unused modules to pull even less power.
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  
  sleep_mode(); // here the device is actually put to sleep!!
 
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_disable(); // first thing after waking from sleep: disable sleep...

  power_all_enable(); // Turn EVERYTHING back on.
}

Thanks in advance,
Jarvis
« Last Edit: November 13, 2010, 10:33:41 am by JSThePatriot » Logged

Pages: 1 ... 9 10 [11]   Go Up
Jump to: