Table of Contents

Oak: using python and Particle.function() to send data to the Oak

In this example, we'll show one way you can make the data sent by the Oak useful with python. You can install python as described in the firmware over serial tutorial. Make sure for the below that you're using python version 2.x (e.g. 2.7), not python v3.

Components used

Part

Quantity

Identification

Oak with solid headers

1

Breadboard

1

Potentiometer

1

Jumper wires

7

Arduino

1

Note: The potentiometer, Arduino, and jumpers are for the purpose of reading the output of a serial device and sending it through python. These are not necessary to send data with python, they're serving as a “data generator” as an example of a potential use.

To verify your python environment, open a Command Prompt or terminal and type python and press enter. If python is working properly, you should enter a session:

If that happens, you're all set! If not, you should get python in order before proceding. Type quit() and press enter to quit this session.

Concepts

python

python is a programming language. It offers a wide range of capabilities through “modules” which can be imported. Since it has wide adoption as a good general programming language and is relatively fast, it is used in many academic and industrial fields. The modules make it very easy to do certain tasks without having to write the code yourself.

For some examples, it is easy to send data to the web with the module requests and easy to read in serial data using pyserial. Since you will often want to use a computer of some sort to act on the data you collect with the Oak, knowing a little about how to program is a a useful skill. python works very well on the Raspberry Pi, which could serve as one way to have a computer on at all times talking to the Oak.

Change the values in the python file and re-run it. You can now use a programming language to send data to your Oak!

Arduino: reading a potentiometer

In this next example, we will use an Aruino as a data generator by reading in the value of a potentiometer with python and the setting the color of our LED based on it's value. Here is the code to send the potentiometer value over serial:

When we have the appropriate code uploaded to both the Arduino and the Oak, we can read the potentiometer, transmit it to the cloud, and have the Oak update based on it's value! I've commented out the line for printing r.text, so this demonstration will only show the RGB values being translated by the Arduino and sent over serial:

Conclusion

Now you know at least one method of relaying data collected locally to the Oak! While this was done with a computer and Arduino, this could have been done even easier with a Raspberry Pi, which can run pythonand has input pins. The Pi could read data from a sensor, and then do something interesting with the Oak which is in a separate location.

On the other hand, being able to do this with an Arduino is useful in that you can now essentially give your Arduino network abilities by leveraging python, and the Arduino makes is super easy to read in all sorts of digital and analog devices. In a final project, having a laptop required as one of the components is obviously not practicle… but the python/Arduino combination can let you do a lot of prototyping before you figure out your final design. What's your next project going to be?