Hi, has anyone got any experience with Arduino and these tools ?
I really like the idea of running all the code on a computer and controlling what the Arduino does from there. Effectively using the Arduino purely as a sensor interface.
Any comments appreciated.
Regards,
cas
I have no experience with to tools you indicate, but I have controlled both Arduino type boards and Rpi's over a network connection via the MQTT communication route. It's very easy to set up and use as long as the boards are network connected of course.
Hi, ok, thanks. I'll take a look at that to see how it works. In reality though, I think I want to do it serially.
Thanks for the heads-up.
Regards,
cas
Hi, has anyone got any experience with Arduino and these tools ?
I really like the idea of running all the code on a computer and controlling what the Arduino does from there. Effectively using the Arduino purely as a sensor interface.
Any comments appreciated.
Regards,
cas
Hi Cas,
I did the control setup for a laser installation that uses Firmata. The controlling computer is a netbook that runs a python script that talks to the Arduino/firmata.
It runs ok and was easy to use. Firmata was chosen because I was only doing the setup and install and others with no electronics or microcontroller experience would be the maintainers.
Do you have any particular questions about it?
Scott
It looks pretty straightforward.
pyfirmata with a Tkinter graphical interface would be quite neat.
Hi there,
thanks for the reply. Well, a few things really.
First-off, I could kill for some real documentation 🙂
Then, the two things I really want to get a handle on is controlling I2C devices and accessing the SPI interface. That kind of thing.
Thanks,
cas
Hi,
I haven't looked at Pyfirmata yet. Do you know if there's much documentation ?
Thanks,
cas
I suggest you start python in the terminal window, call up help() and then modules, and look at the inside of the module.
I think you asking too much of pyfirmata to handle communications with I2C and SPI. My guess you would be better off just setting up pyserial for communications and let Arduino and the wire.h library handle comms with I2C.
What I understand is, that pyfirmata is merely a convenient tool for setting and getting Arduino pins directly from Python. Nothing else.
Hi,
from what I've just looked at, I'd say you're right 🙂 - I'm not a python programmer anyway. Actually, I'm not a programmer of any kind 🙂
That's why I was looking at the processing language.
I've forgotten all the details, but there is a long-standing relationship between the Processing Foundation and the Arduino folks.
I need all the crutches I can get my hands on 🙂
Regards,
cas
For Docs, there is the http://www.firmata.org page, but it covers the protocol mostly. I would say the best thing is to look at the examples from Processing or others like the python's firmata library.
Now, i2c...
I know the StandardFirmataPlus supposedly supports i2c (not sure of SPI), but in most cases, it would not be the best way to interact with those type devices. Many i2c devices need a lot of code to get the data back you need. SPI would be the same.
What I would do is just make an Arduino program that reads/writes the data on command via serial. This would also give you more control on the Arduino side.
If it was just pain ole GPIO, then firmata would be ok, but in this instance, I would opt for the custom code approach. I'm sure that's not what you wanted to hear, but it would not be too hard and is close to what you want.
Scott
Hi Scott.
thanks.
I've done the first route. I wrote a specialised weather station for my son so he could better tune his Kart for racing. It works really well.
There's a bmp280 on the I2C bus and some simple code to read it and spit the data out serially. Processing then does a fair amount of maths and graphs the calculations.
I just thought it would be kinda cool to do the whole thing on the host.
I've just seen a javascript library that I think does what I want but I'll have to do some reading and digging.
Best,
cas
Here is some bare-bones code that you could adapt to suit your need. It was in a sketch that I wrote to handle a real-time clock without using somebody else's library
#include <Wire.h>
int ds3231_address = 0x68; //ds3231 I2C address, change if required.
//Ooops, I forgot to declare the array
byte mByte[0x13]; // create array for the register contents
void setup() {
Wire.begin();
}
void loop(){
// load register values from DS3231
registerToArray();
// this is where you do something with the register values
// write values back to register
writeToRegister();
}
void registerToArray(){
// call this function to initialise or refresh the mByte array
// gets the values from all registers and places them in an array called mByte
Wire.beginTransmission (ds3231_address);
Wire.write (0x00); // Set device to start reading at register 0
Wire.endTransmission ();
// request 19 bytes from the DS3231 and release the I2C bus
Wire.requestFrom(ds3231_address, 0x13, true);
int idx = 0;
// reads the bytes and write them to the mByte array
while(Wire.available()) {
mByte[idx] = Wire.read(); // read each byte from the register
idx++;
}
return;
} // end of registerToArray()
void writeToRegister(){
// call this function if you change any register values
int idx = 0;
// Set the register pointer to 0x00
Wire.beginTransmission (ds3231_address);
Wire.write (0x00);
while(idx < 0x013){
Wire.write(mByte[idx]);
idx++;
}
Wire.endTransmission ();
return;
} // end of writeToRegister()
I hope this might be of some use to you!