Firmata, Node.JS and a PID - Controll on the Arduino Yun

Hey,

i am working on a Project for the University. I am trying to controll a heater with PID while communicating with a web service using Node.JS.

My first approach was a PID Sketch which is working fine on the Arduino. Now i want to be able to set the target temperature via a web service and this is where i started to struggle.

I was able to get Node.JS and Firmata working but my Node.JS - PID Sketch is not working at all.

Now i am wondering if it´s possible to use my already working Arduino PID - Sketch together with the Firmata - Sketch to controll my heater while using Node.JS running on the OpenWRT to communicate with the web-service.

Kind regards, thanks for any help

|500x226

How To Write PID control algorithm using C

Compile C at Yun, leave ATmega32u4 as dummy I/O only.

( Firmata Sketch conflict with PID Sketch is your problem at first place )

Hey,

thanks for the reply.

I 'm not sure whether I have understood everything correctly. So you would write a new PID algorithm, compile it at the YUN, have the Firmata sketch running on the ATmega?

Communication with the Web-Service via Node.JS? Why no PID - Algorithm in Javascript?

The Firmata Sketch conflict with the PID Sketch is the problem when i´m trying to run both on the ATmega, right?

Excuse me for potentially stupid questions but as a mechanical engineering student my progamming knowledge is very limited.

ThereWillBeCake: Hey,

i am working on a Project for the University. I am trying to controll a heater with PID while communicating with a web service using Node.JS.

My first approach was a PID Sketch which is working fine on the Arduino. Now i want to be able to set the target temperature via a web service and this is where i started to struggle.

I was able to get Node.JS and Firmata working but my Node.JS - PID Sketch is not working at all.

Now i am wondering if it´s possible to use my already working Arduino PID - Sketch together with the Firmata - Sketch to controll my heater while using Node.JS running on the OpenWRT to communicate with the web-service.

It seems like you may have misunderstood what Firmata is for.

Basically - firmata is a both a sketch - but also a communication protocol.

Essentially, it's a sketch that runs on an Arduino (although other implementations may be available) that implements this communications protocol - which other libraries which implement the protocol can communicate with (in your case, there is a library for Node.js that implements the firmata protocol).

So - you end up having a process like this:

PC (Yun in your case, running Node.js) -> firmata lib (Node.js) -> (comm channel) -> Arduino -> firmata sketch -> (control of pins)

If I am understanding correctly (and if I have anything wrong, let me know), you have a Yun running Node.js, with the firmata library package installed. This you are using to connect to the Arduino, which is running the firmata sketch.

Now - basically - what you need to do is convert the PID portion over to Node.js to run it on the Yun (that, or set something up on the Yun that runs and communicates thru Node.js - but that seems a bit roundabout to me; while it could be done, it just adds complexity for little gain).

What firmata does is allow you to specify pins to read/write to, and send commands down a communications channel (serial port, ethernet, wifi, bluetooth, etc) - which on the other end, an Arduino (or something else) is running the Firmata sketch (etc) - which then interprets the commands and sets or reads the pins on the Arduino as specified.

You don't need to combine any sketches - Firmata should be the -only- thing running on the Arduino (Uno? Mega? I'm not sure what you are using) - and on the Arduino Yun, you should only be running Node.js with the Firmata library/package installed.

Your PID code (and all your other control logic) would be written in Node.js (aka - javascript) - and would read/write to the other Arduino via Firmata over the communications channel.

You might also better understand this process if you read some of the stuff here:

http://nodebots.io/

This basically uses Firmata, Node.js, and the Johnny-Five module (the Node.js firmata lib) to allow you control a robot. Well - in your case, it's a heater - but it is basically the same idea.

Good luck - and I hope this helps in some manner.

:D

Hey, thanks for the reply. That actually helps alot.

Only thing is that i am not using two Arduinos but only one YUN but i guess this should be no problem since i can use the bridge as communication channel between the two processors if i understood that right.

Thanks alot for your help, guess i need to rewrite my code in Javascript now since i guess it´s not possible to compile my Arduino Sketch into Javascript, am i right?

Kind regards