@@ -10,45 +10,45 @@ The [Ruggeduino](http://ruggedcircuits.com/html/ruggeduino.html)
10
10
provides a total of 18 pins for either digital input or output (labelled 2 to 13 and A0 to A5),
11
11
including 6 for analogue input (labelled A0 to A5).
12
12
13
- The ` ruggeduinos ` object is used to control a collection of Ruggeduinos.
14
- Similar to ` motors ` and ` servos ` , ` ruggeduinos ` can be used like a list.
15
- To do something with the ** first Ruggeduino** , you would use:
13
+ When a single Ruggeduino is connected to your robot, you can control it
14
+ using the ` ruggeduino ` object.
16
15
17
16
~~~~~ python
18
- R.ruggeduinos[ 0 ] .something...
17
+ R.ruggeduinos.something...
19
18
~~~~~
20
19
21
- ...because indexes are 0-based (counting starts from 0, not 1).
22
-
23
- When you have more than one Ruggeduino board connected to your kit
24
- they will be ordered based upon their serial number.
25
-
26
20
The serial number of each detected Ruggeduino is printed to the log when your robot starts.
27
21
It will look something like this:
28
22
29
23
~~~~~ not-code
30
- Found the following devices:
31
- - Ruggeduinos:
32
- 0: Ruggeduino( serialnum = "752303138333517171B1" )
24
+ sr.robot3.robot INFO - Found Ruggeduino - 752303138333517171B1
33
25
~~~~~
34
26
35
- In addition, like ` motors ` , ` ruggeduinos ` is actually a dictionary.
36
- As a result, in ` ruggeduinos ` you can also use the Ruggeduino serial number as a key.
27
+ If you have more than one Ruggeduino attached, the ` ruggeduinos ` object
28
+ can be used to control a collection of Ruggeduinos. Similar to ` motors `
29
+ and ` servos ` , ` ruggeduinos ` is a dictionary accessed by serial number.
37
30
For example, if you had a board whose serial number was "752303138333517171B1",
38
31
you could do this instead:
39
32
40
33
~~~~~ python
41
34
R.ruggeduinos[" 752303138333517171B1" ].something...
42
35
~~~~~
43
36
37
+ <div class =" warning " >
38
+ When you have more than one Ruggeduino board connected to your kit,
39
+ you must use `R.ruggeduinos` and index by serial number. This is so
40
+ that the kit knows which Ruggeduino you want to control.
41
+ </div >
42
+
43
+
44
44
[ Setting pin modes] ( #pinmodes ) {#pinmodes}
45
45
--------------------------------------------------------------------------
46
46
47
47
To use one of the pins on the Ruggeduino, you must first set whether you want it to behave as an input or as an output.
48
48
You can do this with the following code:
49
49
50
50
~~~~~ python
51
- R.ruggeduinos[ RUGGEDUINO_BOARD_NUMBER ].pin_mode( PIN_NO , MODE )
51
+ R.ruggeduino.pins[ 10 ].mode = MODE
52
52
~~~~~
53
53
54
54
The possible values for ` MODE ` are:
@@ -65,12 +65,12 @@ The possible values for `MODE` are:
65
65
An example of how to use this is below:
66
66
67
67
~~~~~ python
68
- # set Ruggeduino board 0's pin 2 to output
69
- R.ruggeduinos[ 0 ].pin_mode( 2 , OUTPUT )
70
- # set Ruggeduino board 0's pin 3 to input
71
- R.ruggeduinos[0 ].pin_mode( 3 , INPUT )
72
- # set Ruggeduino board 0's pin 4 to input and enable pull-up resistor
73
- R.ruggeduinos[0 ].pin_mode( 4 , INPUT_PULLUP )
68
+ # set Ruggeduino pin 2 to output
69
+ R.ruggeduino.pins[ 2 ].mode = OUTPUT
70
+ # set Ruggeduino pin 3 to input
71
+ R.ruggeduinos[0 ].pins[ 3 ].mode = INPUT
72
+ # set Ruggeduino git commit -m " pin 4 to input and enable pull-up resistor
73
+ R.ruggeduinos[0 ].pins[ 4 ].mode = INPUT_PULLUP
74
74
~~~~~
75
75
76
76
<div class =" warning " >You cannot use pins 0 and 1, as using these would disrupt communications between the Ruggeduino and the Power Board.</div >
@@ -81,37 +81,39 @@ R.ruggeduinos[0].pin_mode(4, INPUT_PULLUP)
81
81
You can read a ** digital** input pin with the following code:
82
82
83
83
~~~~~ python
84
- # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].digital_read(PIN_NO )
84
+ # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO]. digital_read()
85
85
86
- # to read Ruggeduino board 0 's digital pin 3...
87
- pin0 = R.ruggeduinos[ 0 ].digital_read(3 )
86
+ # to read Ruggeduino's digital pin 3...
87
+ pin0 = R.ruggeduino.pins[ 3 ].digital_read()
88
88
~~~~~
89
89
90
90
` pin0 ` will now contain ` True ` or ` False ` depending on whether the pin was high (3.3v) or low (0v), respectively.
91
91
92
92
You can read an ** analogue** input pin with the following code:
93
93
94
94
~~~~~ python
95
- # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].analogue_read(PIN_NO )
95
+ # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO]. analogue_read()
96
96
97
- # to read Ruggeduino board 0 's analogue pin A0...
98
- pin0 = R.ruggeduinos[ 0 ].analogue_read(0 )
97
+ # to read Ruggeduino's analogue pin A0...
98
+ pin0 = R.ruggeduino.pins[A0 ].analogue_read()
99
99
~~~~~
100
100
101
+ The analogue pin numbers are available as ` A0 ` , ` A1 ` , ` A2 ` , ` A3 ` , ` A4 ` , and ` A5 ` respectively.
102
+
101
103
102
104
[ Output] ( #output ) {#output}
103
105
--------
104
106
105
107
You can only set digital outputs (there's no analogue output, although you may feel free to modify the Ruggeduino's firmware to add the ability to output [ PWM] ( https://wikipedia.org/wiki/Pulse-width_modulation " Pulse-width modulation ") if you desire). To set a digital output pin, you would use the following:
106
108
107
109
~~~~~ python
108
- # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].digital_write(PIN_NO, VALUE)
110
+ # R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO]. digital_write(VALUE)
109
111
110
- # to set Ruggeduino board 0's pin 2 high:
111
- R.ruggeduinos[0 ].digital_write(2 , True )
112
+ # to set Ruggeduinos pin 2 high:
113
+ R.ruggeduinos[0 ].pins[ 2 ]. digital_write(True )
112
114
113
- # to set Ruggeduino board 0 's pin 2 low:
114
- R.ruggeduinos[0 ].digital_write(2 , False )
115
+ # to set Ruggeduino's pin 2 low:
116
+ R.ruggeduinos[0 ].pins[ 2 ]. digital_write(False )
115
117
~~~~~
116
118
117
119
[ Pull-up resistors] ( #pullup ) {#pullup}
0 commit comments