[SOLVED] Startup help please. Reading serial data from a pin.

Hello,

I'm a Arduino Yun newbie, building a project to read data from a 433 mHz unit.
A shield has been build that picks up the data from the air and delivers it to digital pin 2.
This pin has been chosen for it being an interrupt pin. I'm free to use an other pin if that would be better.

The shield has been tested by reading data on a PC and is working okay.
(Data comes in on 4800 bps, E, 1)

I'm looking for a usable sample code to boot be in the right direction please.
Can anybody help me by directing me to some sample code I can use to learn?

Thanks in advance.

Rens

Have a look at Software Serial,


Rob

VirtualWire is what you need and it has no need for a shield just connect your Rx to the arduino.

Or maybe you should tells more about the shield you have constructed.

Mark

holmes4:
Maybe you should tells more about the shield you have constructed.

The shield is just a very simple 433 mHz receiver that is used in am other device for some years now. It does it's job very good and has proven to be stable. I have checked the data on a terminal and it is okay. Now, the data out has been connected to D2 on the Arduino. That's about all. :slight_smile:

The shield is just a very simple 433 mHz receiver

I doubt very much that it is. :wink:

You doubt it is simple? :relaxed:

No, I doubt it is 433mHz. :wink:

AWOL:
No, I doubt it is 433mHz. :wink:

O..... Okay.........
First: It does not affect the working of the setup.
Data is coming in at 4800 Bps, E, 1, no matter what the source is.
It could even be a lady behind a old fashion teletype sending data.
:slight_smile:

Second: Why do you doubt the 433 mHz?
What am I missing or saying wrong in your opinion?
:cold_sweat:

Third: The only reason I call it a 'Shield', is because it snaps onto the Arduino.
It would work just as easy it it would be placed next to the Arduini and just has GND and the data out connected to the Arduino.
Prototyping optima forma.
:smiley:


Friendly greetings
Rens

Second: Why do you doubt the 433 mHz?

Because even a quarter wave antenna would be 173 000 km long, which would be inconvenient.

What am I missing

A capital "M".

AWOL:

Second: Why do you doubt the 433 mHz?

Because even a quarter wave antenna would be 173 000 km long, which would be inconvenient.

What am I missing

A capital "M".

Okay..... I stand corrected. :zipper_mouth_face:

Back to coding? :astonished:

If you've got a terminal or other simple text protocol on the other end of the link, then VirtualWire isn't going to be of much use, so I'd go with SoftwareSerial.
If you have better control of the far end (like another Arduino) then VirtualWire is probably the better option.

(the reason I get picky is mostly because I work on products where frequencies can be specified from mHz to GHz, so it is important to get the units right. )

Okay..... SoftwareSerial it is.

So I'm using the following sample, that puts me into trouble right away. :relaxed:

/*
  Based upon the Serial Event example by Tom Igoe
 */
#include <SoftwareSerial.h>
// [RensD] software serial config: 
// [RensD] TX-pin (Not used, so just init it on pin 3
// [RensD] RX-pin init on pin 2
SoftwareSerial portOne(3,2);

String inputString = "";                  // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString); 
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read(); 
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    } 
  }
}

What happens?
When the Arduino is NOT running and I trigger the transmitter, I see data coming in op my terminal software.....

When I run the Arduino Sketch, everything is silent.
The Arduino sees no data, and neither does the Terminal software anymore.

Other pin settings
When I set the pins to for instance SoftwareSerial portOne(4,3);
The Aduino still does not receive anything (off cause) but the terminal software sees data again.

Solution?
Does the Arduino short cicuit the pin?
Do I have to place a resitor of some kind?
Please help.

Friendly greetings
Rens

Try connecting the receiver tx to the arduino rx, connect the grounds, set the baude rate, and try the below echo code to see what you get in the serial monitor.

//zoomkat serial echo test 7-31-2011

char input; // incoming serial data
//byte input; // incoming serial data

void setup() {
  Serial.begin(9600);	// set serial port at desired value
  Serial.println("serial echo test 0021"); // echo test
  }

void loop() {
  if (Serial.available() > 0) { // check for serial buffer input
    input = Serial.read(); // read the rx incoming byte 
    //Serial.write(input); // print the input to tx output
    Serial.print(input); // print the input to tx output
  }
}

zoomkat:
Try connecting the receiver tx to the arduino rx, connect the grounds, set the baude rate, and try the below echo code to see what you get in the serial monitor.

Same issue.
Data comes in on the terminal program.
Running the Sketch on the Arduino..... No data anymore.

I'm puzzled by your comment that the serial output stops when you run the Arduino. As I understand the serial output is coming from the Arduino, so perhaps I've understood it wrong. From what you have said so far I have guessed the following setup:

RF receiver generating serial output at 4800 bps, even parity, 1 stop bit.
Serial tx pin connected to Arduino digital pin 2.
SoftwareSerial instance configured with digital pin 2 as the Rx pin.
After that is a mystery. You say:

When the Arduino is NOT running and I trigger the transmitter, I see data coming in op my terminal software

Where is the terminal software running, and what is it reading from? What do you mean by the Arduino 'not running'? If you mean it's powered off or disconnected from the USB, the associated virtual serial port should have disappeared. The symptoms suggest you may be reading from floating pins and be generating noise which occasionally has valid parity, but I can't visualise your setup well enough to know if that's feasible. I also wonder whether/how you have persuaded SoftwareSerial to use even parity and one stop bit, and what serial port settings your terminal software is using. If these don't match what the Arduino is sending then you're liable to get nothing, or garbage.

If all you want is to use the Arduino as a serial TTL-to-USB converter then you could connect the shield's Tx pin to the Arduino's Tx pin (1) and hold the Arduino in reset. On Arduinos with a separate USB driver, that would just pass everything over USB. I don't know whether that's the case with the Yun, though.

Okay.... I see the confusion.
Please let me elaborate in this.

Configuration
I have a transmitter.
Small standalone box.

This box sends a small data string over the air every few hours.


We created a small shield that contains a receiver.
(This PCB can work standalone as well, but is plugged into the Arduino connectors, hence shield)

Checking the over the air data transmission
I have a laptop with a terminal program via cable connected to the receiver.
This terminal program shows the data string correct whenever the transmitter sends it's string.
Hence..... The transmitter works and the receiver works.
This cable connection and terminal software is just for debugging purposes and will not be part of the final design.

The pin the terminal is listening on, is also connected to the Arduino pin D2. (And ground is connected as well off cause)

Start testing sketches.........
When I load the SoftwareSerial example that came with the library, I compile it as is and run it.
The terminal software still receives data and shows it.
The Arduino does not see any data. Logical, it shouldn't, since it standard listens on pin D10, and the receiver is connected to pin D2.

Than I test on the correct pin.
I alter the
"SoftwareSerial mySerial(10, 11); // RX, TX"
line to
"SoftwareSerial mySerial(2, 3); // RX, TX"

From that moment on, the terminal software does not see any data coming in anymore.
The Arduino does not see any data either.
So I suspect the Arduino short circuits the pin or something like that.

Question
What is wrong? How do I solve this?

Friendly greetings and thanks for the assistance,
Rens

The Rx pin used by the SoftwareSerial would be in input mode, meaning it's a high impedance. Usually that would prevent it from affecting the circuit it is connected to. The Tx pin would be configured as an output and driven low when it was idle. Does your shield make any connection to pin 3?

Why not make life easy and move the wires to some unused pins? After all that's the main purpose of Software Serial.


Rob

I have a laptop with a terminal program via cable connected to the receiver.
This terminal program shows the data string correct whenever the transmitter sends it's string.
Hence..... The transmitter works and the receiver works.
This cable connection and terminal software is just for debugging purposes and will not be part of the final design.

The pin the terminal is listening on, is also connected to the Arduino pin D2. (And ground is connected as well off cause)

Looks like you have an rs232 output from the receiver, which probably works with the pc serial port, but would not work with a TTL rx on the arduino without be converted.

PeterH:
Does your shield make any connection to pin 3?

No.... It's just hanging in the air. I tell the software to use 3, because I have to set it to some pin, and that one is fee.