Skip to content

Commit 6d8aca4

Browse files
committed
Update ruggeduino API for SR2022
1 parent b7abd9c commit 6d8aca4

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

programming/sr/ruggeduinos/index.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,45 @@ The [Ruggeduino](http://ruggedcircuits.com/html/ruggeduino.html)
1010
provides a total of 18 pins for either digital input or output (labelled 2 to 13 and A0 to A5),
1111
including 6 for analogue input (labelled A0 to A5).
1212

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.
1615

1716
~~~~~ python
18-
R.ruggeduinos[0].something...
17+
R.ruggeduinos.something...
1918
~~~~~
2019

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-
2620
The serial number of each detected Ruggeduino is printed to the log when your robot starts.
2721
It will look something like this:
2822

2923
~~~~~ not-code
30-
Found the following devices:
31-
- Ruggeduinos:
32-
0: Ruggeduino( serialnum = "752303138333517171B1" )
24+
sr.robot3.robot INFO - Found Ruggeduino - 752303138333517171B1
3325
~~~~~
3426

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.
3730
For example, if you had a board whose serial number was "752303138333517171B1",
3831
you could do this instead:
3932

4033
~~~~~ python
4134
R.ruggeduinos["752303138333517171B1"].something...
4235
~~~~~
4336

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+
4444
[Setting pin modes](#pinmodes) {#pinmodes}
4545
--------------------------------------------------------------------------
4646

4747
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.
4848
You can do this with the following code:
4949

5050
~~~~~ python
51-
R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pin_mode(PIN_NO, MODE)
51+
R.ruggeduino.pins[10].mode = MODE
5252
~~~~~
5353

5454
The possible values for `MODE` are:
@@ -65,12 +65,12 @@ The possible values for `MODE` are:
6565
An example of how to use this is below:
6666

6767
~~~~~ 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
7474
~~~~~
7575

7676
<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)
8181
You can read a **digital** input pin with the following code:
8282

8383
~~~~~ python
84-
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].digital_read(PIN_NO)
84+
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO].digital_read()
8585

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()
8888
~~~~~
8989

9090
`pin0` will now contain `True` or `False` depending on whether the pin was high (3.3v) or low (0v), respectively.
9191

9292
You can read an **analogue** input pin with the following code:
9393

9494
~~~~~ python
95-
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].analogue_read(PIN_NO)
95+
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO].analogue_read()
9696

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()
9999
~~~~~
100100

101+
The analogue pin numbers are available as `A0`, `A1`, `A2`, `A3`, `A4`, and `A5` respectively.
102+
101103

102104
[Output](#output) {#output}
103105
--------
104106

105107
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:
106108

107109
~~~~~ python
108-
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].digital_write(PIN_NO, VALUE)
110+
# R.ruggeduinos[RUGGEDUINO_BOARD_NUMBER].pins[PIN_NO].digital_write(VALUE)
109111

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)
112114

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)
115117
~~~~~
116118

117119
[Pull-up resistors](#pullup) {#pullup}

0 commit comments

Comments
 (0)