1

Good day, I have a serial device that when connected via hyper terminal gives me a status report when I press the letter 'd' no enter key or anything required just the letter d. Also Ctrl-t will give me some routing information.

I would like to press a button connected to the arduino and send the b to the serial device and view the status information back from it.

At this point I have the Serial device connected to the arduino and am able to see messages from it, however when I press the switch connected to pin 2 the serial device does not send me the status output as expected and as seen via direct serial connection to my computer with hyperterminal.

Does anyone have an experience or input regarding this?

#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
 SoftwareSerial portOne(10, 11);
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int button1Pin = 4;
 const int ledPin =  13;      // the number of the LED pin
//define char to send to serial

char stat = 'd';
char route = '\x14';
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int button1State = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
                pinMode(ledPin, OUTPUT);
                pinMode(buttonPin, INPUT);
                pinMode(button1Pin, INPUT);
                Serial.begin(4800);
                while (!Serial) {; // wait for serial port to connect. Needed for native USB port only
                }
                // Start each software serial port
                portOne.begin(4800);
                while (!portOne) {; // wait for serial port to connect. Needed for native USB port only
                }
              }

// the loop function runs over and over again forever
void loop() {
            static int Once = 0;
            static int Once1 = 0;
            buttonState = digitalRead(buttonPin);
            button1State = digitalRead(button1Pin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
            if (buttonState == HIGH ) { 
                                      if (Once == 0) {
                                                        Once = 1;
                                                        // turn LED on so I can tell the button is working
                                                        digitalWrite(ledPin, HIGH);
                                                        // send d to Radio
                                                        portOne.write(stat);
                                                        // send d to serial monitor so I can see the charector
                                                        Serial.print(stat);
                                      }
                                      }


if (buttonState == LOW) {
                          // turn LED off:
                          Once = 0;
                          digitalWrite(ledPin, LOW);

                          }


  // check if the other pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (button1State == HIGH) {
    if (Once1 == 0) {
          Once1 = 1;
    // turn LED on:
   // digitalWrite(ledPin, HIGH);
    // send ctrl-t to radio
    portOne.write(route);
    } 
  }
  if (button1State == LOW) {
    // turn LED off:
    //digitalWrite(ledPin, LOW);
    Once1 = 0;
  }
    portOne.listen();
      // read data from the Software Serial portOne
   // and send to the hardware serial port:
   while (portOne.available() > 0) {
     char inByte = portOne.read();
     Serial.print(inByte);
   }
}

Breadboard

  • Maybe add a while(Serial.available())portOne.print(Serial.read()); to allow you to inject characters from the serial monitor to you device. Then you could bypass potential issues with bouncing/debouncing. – Dave X Mar 9 '16 at 19:08
  • I see what your saying however I think its more of a problem getting the char passed to the serial device. You see if I change char stat from 'd' to 'c' this should "enable monitor all" however this doesn't happen, so i'm guessing either the char isn't getting to the device or its garbled some how... – Tony M Mar 9 '16 at 19:31
  • We should be seeing a Ground wire going to the device. As a convention, you should connect 5V to the red line on the breadboard, and Gnd to blue. It is confusing to reverse that. Please add some debugging displays, eg. Serial.println ("Sending 'd' to device"); - then you'll know if it is a switch-detection issue, or a comms issue. – Nick Gammon Mar 9 '16 at 20:05
  • In your intro you wrote "gives me a status report when I press the letter 'b'". In the code you wrote // send d to Radio (and the code appears to actually do that). Is this correct, and could that be the source of your error? – JRobert Mar 9 '16 at 20:20
  • 1
    It was not entirely clear from your question, but have you verified that the signalling voltage and polarity of the serial device is compatible with the Arduino? Traditional serial interfaces (ie RS232, etc) are not, and require an inverting level translator to interface with an Arduino. – Chris Stratton Mar 9 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.