-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
266 lines (204 loc) · 10.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="./img/favicon.ico">
<title>Nanpy</title>
<link href="./css/bootstrap-custom.min.css" rel="stylesheet">
<link href="./css/font-awesome-4.0.3.css" rel="stylesheet">
<link href="./css/prettify-1.0.css" rel="stylesheet">
<link href="./css/base.css" rel="stylesheet">
<link href="./css/extra.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body class="homepage">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Main title -->
<a class="navbar-brand" href=".">Nanpy</a>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/nanpy/">
<i class="fa fa-github"></i>
GitHub
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="col-md-3"><div class="bs-sidebar hidden-print affix well" role="complementary">
<ul class="nav bs-sidenav">
<li class="main active"><a href="#nanpy">Nanpy</a></li>
<li><a href="#overview">Overview</a></li>
<li><a href="#how-to-build-and-install">How to build and install</a></li>
<li><a href="#how-to-contribute">How to contribute</a></li>
<li><a href="#how-to-extend-nanpy">How to extend Nanpy</a></li>
<li><a href="#license">License</a></li>
</ul>
</div></div>
<div class="col-md-9" role="main">
<h1 id="nanpy">Nanpy</h1>
<p>Use your Arduino board with Python.</p>
<hr />
<h2 id="overview">Overview</h2>
<p>Nanpy is a library that use your Arduino as a slave, controlled by a master device where you run your scripts, such as a PC, a Raspberry Pi etc.
The main purpose of Nanpy is making programmers' life easier, providing them a powerful library to create prototypes faster and make Arduino programming a game for kids.</p>
<pre class="prettyprint well"><code>a = ArduinoApi()
a.pinMode(13, a.OUTPUT)
a.digitalWrite(13, a.HIGH)
</code></pre>
<p>I know, there are a lot of projects able to do that, but hey, Nanpy can do more!
Nanpy is easily extensible and can theoretically use every library, allowing you to create how many objects you want.
We support OneWire, Lcd, Stepper, Servo, DallasTemperature and many more...
Let's try to connect our 16x2 lcd screen on pins 7, 8, 9, 10, 11, 12 and show your first "Hello world"!</p>
<pre class="prettyprint well"><code>from nanpy import Lcd
lcd = Lcd([7, 8, 9, 10, 11, 12], [16, 2])
lcd.printString('Hello World!')
</code></pre>
<p>really straightforward now, isn't it? :)</p>
<h3 id="serial-communication">Serial communication</h3>
<p>Nanpy autodetects the serial port for you, anyway you can manually specify another serial port:</p>
<pre class="prettyprint well"><code>from nanpy import SerialManager
connection = SerialManager(device='/dev/ttyACM1')
</code></pre>
<p>and use it with your objects</p>
<pre class="prettyprint well"><code>a = ArduinoApi(connection=connection)
a.pinMode(13, a.OUTPUT)
a.digitalWrite(13, a.HIGH)
</code></pre>
<p>You can specify how many SerialManager objects you want and control more than one Arduino board within the same script.</p>
<hr />
<h2 id="how-to-build-and-install">How to build and install</h2>
<p>First of all, you need to build the firmware and upload it on your Arduino, to do that clone the <a href="https://github.com/nanpy/firmware">nanpy-firmware repository on Github</a> or <a href="https://pypi.python.org/pypi/nanpy">download it from PyPi</a>.</p>
<pre class="prettyprint well"><code>git clone [email protected]:nanpy/nanpy-firmware.git
cd nanpy-firmware
./configure.sh
</code></pre>
<p>You can now edit Nanpy/cfg.h generated file to configure your Nanpy firmware, selecting the features you want to include and the baud rate.
To build and install Nanpy firmware, copy Nanpy directory under your "sketchbook" directory, start your Arduino IDE, open Sketchbook -> Nanpy and click on "Upload".</p>
<p>To install Nanpy Python library on your master device just type:</p>
<pre class="prettyprint well"><code>pip install nanpy
</code></pre>
<hr />
<h2 id="how-to-contribute">How to contribute</h2>
<p>Nanpy still needs a lot of work. You can contribute with patches (bugfixing, improvements, adding support for a new library not included in Nanpy yet, writing examples and so on), writing documentation, reporting bugs, creating packages or simply spreading Nanpy through the web if you like it :) If you have any doubt or problem, please contact me at <a href="mailto:stagi.andrea@gmail.com">stagi.andrea@gmail.com</a></p>
<p>Do you want to support us with a coffee? We need a lot of caffeine to code all night long! if you like this project and you want to support us, <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TDTPP5JHVJK8J">please donate using Paypal</a></p>
<hr />
<h2 id="how-to-extend-nanpy">How to extend Nanpy</h2>
<p>First of all create some boilerplate code starting with Python. Suppose you want initially support two methods of the Centpiede library</p>
<pre class="prettyprint well"><code>void portWrite(int port, int value);
int portRead(int port);
</code></pre>
<p>You can create your centipede.py module and put it in nanpy/</p>
<pre class="prettyprint well"><code>from nanpy.arduinoboard import ArduinoObject
from nanpy.arduinoboard import (arduinoobjectmethod, returns)
class Centipede(ArduinoObject):
def __init__(self, your_parameters connection=None):
ArduinoObject.__init__(self, connection=connection)
self.id = self.call('new', your_parameters)
@arduinoobjectmethod
def portWrite(self, port, value):
pass
@returns(int)
@arduinoobjectmethod
def portRead(self, port):
pass
</code></pre>
<p>After that you can include this module in the <strong>init</strong>.py to make it available in Nanpy (nanpy/<strong>init</strong>.py https://github.com/nanpy/nanpy/blob/master/nanpy/<strong>init</strong>.py)</p>
<pre class="prettyprint well"><code>from nanpy.centipede import Centipede
</code></pre>
<p>You're done with Python :) Let's see how to add the firmware part (https://github.com/nanpy/nanpy-firmware)</p>
<p>First of all modify sample.cfg adding</p>
<pre class="prettyprint well"><code>#define USE_Centipede 1
</code></pre>
<p>or do it directly on your cfg.h file :)</p>
<p>You need to create CentipedeClass.h and CentipedeClass.cpp</p>
<p>In CentipedeClass.h you need</p>
<pre class="prettyprint well"><code>#ifndef CENTIPEDE_CLASS
#define CENTIPEDE_CLASS
#include "BaseClass.h"
#include "MethodDescriptor.h"
class Centipede;
namespace nanpy {
class CentipedeClass: public ObjectsManager<Centipede> {
public:
void elaborate( nanpy::MethodDescriptor* m );
const char* get_firmware_id();
};
}
#endif
</code></pre>
<p>And in Centipede.cpp</p>
<pre class="prettyprint well"><code>#include "cfg.h"
#if USE_Centipede
#include <Arduino.h>
#include <Centipede.h> //!!!Your real Centipede Library!!!!
#include "CentipedeClass.h"
#include <stdlib.h>
const char* nanpy::CentipedeClass::get_firmware_id()
{
return "Centipede";
}
void nanpy::CentipedeClass::elaborate( MethodDescriptor* m ) {
ObjectsManager<Centipede>::elaborate(m);
if (strcmp(m->getName(),"new") == 0) {
Centipede* cent;
cent = new Centipede (m->getInt(0), m->getInt(1), m->getInt(2));
cent->begin();
v.insert(cent);
m->returns(v.getLastIndex());
}
if (strcmp(m->getName(), "portWrite") == 0) {
m->returns(v[m->getObjectId()]->portWrite(m->getInt(0), m->getInt(1)));
}
if (strcmp(m->getName(), "portRead") == 0) {
m->returns(v[m->getObjectId()]->portRead(m->getInt(0)));
}
};
#endif
</code></pre>
<p>Finally you need to register your class in the main loop! Open Nanpy.ino file and add</p>
<pre class="prettyprint well"><code>//...
#if USE_Centipede
#include <Centipede.h>
#endif
#include "CentipedeClass.h"
//...
REGISTER_CLASS_CONDITIONAL(CentipedeClass, USE_Centipede);
</code></pre>
<hr />
<h2 id="license">License</h2>
<p>This software is released under MIT License. Copyright (c) 2012-2014 Andrea Stagi <a href="mailto:stagi.andrea@gmail.com">stagi.andrea@gmail.com</a></p>
</div>
</div>
<footer class="col-md-12">
<hr>
<p>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.</p>
</footer>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="./js/bootstrap-3.0.3.min.js"></script>
<script src="./js/prettify-1.0.min.js"></script>
<script src="./js/base.js"></script>
</body>
</html>