py-arduino access Arduino from Python
How to install py-arduino
Common problems
py_arduino.cli.*: How to use
py_arduino.cli.*: Reference
~/$ cd py-arduino
~/py-arduino$ . virtualenv/bin/activate
~/py-arduino$ python -m examples.read_lm35_basic /dev/ttyACM0
PIN = 0
class Main(BaseMain):
<span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">arduino</span><span class="p">):</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">arduino</span><span class="o">.</span><span class="n">analogRead</span><span class="p">(</span><span class="n">PIN</span><span class="p">)</span>
<span class="n">temp</span> <span class="o">=</span> <span class="p">(</span><span class="mf">5.0</span> <span class="o">*</span> <span class="n">value</span> <span class="o">*</span> <span class="mf">100.0</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1024.0</span>
<span class="k">print</span><span class="p">(</span><span class="s">"Temperature: {0:3.2f} C"</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">temp</span><span class="p">)</span>
if name == 'main': Main().start()