Arduino serial in and a pin out crashes Adruino

155 views
Skip to first unread message

Rania Labib

unread,
Mar 21, 2017, 2:49:07 AM3/21/17
to Node-RED

'm trying to create a very simple flow to test my arduino. First, I added a serial node to receive ultrasonic sensor readings (connected to my arduino), I was able to successfully display the readings . Then as soon as I added an arduino pin (out) node, and selected my board from the drop down list, my arduino and node red crashed . Any suggestions?


Dave C-J

unread,
Mar 21, 2017, 4:47:06 AM3/21/17
to node...@googlegroups.com
Hi,
ah right yes... - the Arduino GPIO type nodes require the Arduino to be running firmata and grab the USB port to talk to it... - likewise the standard serial in is trying to grab the same port. So... question is what is the code running on the Arduino ? 

If it's your own code then the answer is that you also have to handle reading and writing the pins and add them to your stream of serial messages (using the serial out node). 

If it's some other built in firmata like thing that does the range detection , can you share a pointer ?

Mitul Tyagi

unread,
Mar 21, 2017, 5:35:46 AM3/21/17
to Node-RED
Even I am facing the same problem. Earlier this worked nicely with no crashes but now everytime node-red crashes. And firmata is not required if we are working with serial nodes.

Rania Labib

unread,
Mar 21, 2017, 12:10:54 PM3/21/17
to Node-RED
Thanks Dave for your help. The answer is yes I'm running my code, which is a code that measures distance using Parallax PING))) sensor. I'm still testing simple settings because I have never hooked up an Arduino to my Raspberry Pi before, let alone use Node-Red which I'm still learning! Thanks for explaining the issue behind it, that makes sense now. I just can't wrap my mind on how to use the Serial out yet! if I need to send a simple code like the one below via serial out, how would I accomplish this?

void loop() {
  digitalWrite(9, HIGH);
  delay(1);          
  digitalWrite(9, LOW); 
  delay(1);          
}

Julian Knight

unread,
Mar 21, 2017, 4:22:26 PM3/21/17
to Node-RED
Here is the lowdown on serial input to the Arduino:


You don't need the Arduino node for this - as Dave says, this is if you are running Firmata on your Arduino (https://github.com/firmata/arduino)

All you need to do is make sure that the serial out has the correct settings to match what you've set for the serial port in your Arduino code. Then you can send data to that node - usually a text string - and it will be available to be read in the loop function of the Arduino code as in the linked article.

Dave C-J

unread,
Mar 21, 2017, 7:26:04 PM3/21/17
to node...@googlegroups.com
So, yes... As per Julian note above... Then... You will need to decide how you want to encode the message going to the arduino.   If only ever to one pin then you can just send a 0 or 1 etc. But if you want to talk to more pins then... It gets more interesting :-)
You could send the pin number, value - or a string of 0s and 1s to represent values, or encode them all into a single number where each binary bit represents a pin... All good fun. 

(Must admit I tend to go for something simple like just the pin number and the value and don't use pins above 9 so it's only one character long, so first char is the pin and second is 0 or 1.). So "41" is turn on pin 4. But of course half the fun is making it up as you go..

Rania Labib

unread,
Mar 21, 2017, 8:24:36 PM3/21/17
to Node-RED

Dave and Julian, Thank you so much for your help. After reading your input I realized that serial input works pretty much like Python's raw input, and it all dependes on parsing the input using the C code! I really like Dave's idea of sending one number such as "41" then parsing the input using coding. I'm new to arduino, didn't like arduino because I didn't like C. I know more Python than C. I'm also relatively new to programming in general. But both of your inputs helped me understand how serial input works! Awsome!  

Julian Knight

unread,
Mar 21, 2017, 8:38:42 PM3/21/17
to Node-RED
I also hate C++ so I sympathise. I've learned a great many computer languages over the years, even APL which Dave may recognise as it was an IBM staffer who invented it. 

However, even I have to admit that it isn't too hard to learn enough for most Arduino code - though I still have issues with the different handling of strings. Too bizarre.

I use custom code for my sensor platforms - they have multiple sensors and send out JSON. I'll admit though, I've never got round to doing much with serial input. Recently I've moved to using ESP8266 devices with MQTT so serial in/out isn't an issue any more & commands are as easy as subscribing to a topic.

Rania Labib

unread,
Mar 21, 2017, 9:13:13 PM3/21/17
to Node-RED
I just looked up ESP8266 and it looks interesting, worth the learning curve! I learn something new every day on this forum!

Julian Knight

unread,
Mar 22, 2017, 4:27:54 AM3/22/17
to Node-RED
Oh yes!

If you do get into it, the Wemos D1 Mini is about the easiest and most reliable platform for it as it has all the power management sorted and still only costs pennies. You have to order it from AliExpress though so depending on your location, it can be a bit of a wait. ESP8266 devices can be a bit picky about power supplies - not a problem if you know some electronics but it caused me a lot of hassles getting going. There are also some really cheap but good mains switches that use it, search for SONOFF. It is harder to get a wifi based device to be battery powered as they tend to use more power and wifi connections take a few seconds each time but that is rarely an issue now that Lion and Lipo batteries are cheap. Wemos do a battery hat for the D1 mini.

Nice thing is that you can programme them using the same IDE as the Arduino.

Nick who is one of the key devs for Node-RED wrote an Arduino library for MQTT which works well with the ESP8266 devices so both output and input is really easy. It is also easy to create a simple web interface. Even over the air firmware updates are fairly easy to do.
Reply all
Reply to author
Forward
0 new messages