Skip to content

Commit 04ac434

Browse files
authored
Merge pull request #217 from sourcebots/arduino-fixes
Rewrite arduino page to align with sbot
2 parents b4f124f + 1de8510 commit 04ac434

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

docs/programming/arduino.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The [Arduino](https://store.arduino.cc/arduino-uno-rev3) provides a
44
total of 18 pins for either digital input or output (labelled 2 to 13
5-
and A0 to A5), including 6 for analogue input (labelled A0 to A5).
5+
and A0 to A5), pins A0 to A5 also support analog input.
66

77
!!! warning
88
Digital pins 0 and 1 are reserved and cannot be used.
@@ -23,7 +23,7 @@ rest of our kit.
2323

2424
## Pin Mode
2525

26-
GPIO pins have four different modes. A pin can only have one mode at a
26+
GPIO pins have different modes. A pin can only have one mode at a
2727
time, and some pins aren't compatible with certain modes. These pin
2828
modes are represented by an
2929
[enum](https://docs.python.org/3/library/enum.html) which needs to be
@@ -34,7 +34,8 @@ from sbot import GPIOPinMode
3434
```
3535

3636
!!! tip
37-
The input modes closely resemble those of an Arduino. More information on them can be found in [their docs](https://www.arduino.cc/en/Tutorial/DigitalPins).
37+
The input modes closely resemble those of an Arduino.
38+
More information on them can be found in [their docs](https://www.arduino.cc/en/Tutorial/DigitalPins).
3839

3940
### Setting the pin mode
4041

@@ -43,77 +44,76 @@ performing an action with that pin. You can read about the possible pin
4344
modes below.
4445

4546
``` python
46-
robot.arduino.pins[3].mode = GPIOPinMode.DIGITAL_INPUT_PULLUP
47+
robot.arduino.pins[3].mode = GPIOPinMode.INPUT_PULLUP
4748
```
4849

49-
### `GPIOPinMode.DIGITAL_INPUT`
50+
### Digital Input
5051

51-
In this mode, the digital state of the pin (whether it is high or low)
52-
can be read.
52+
Digital inputs can be used to check the state of a pin (whether it is high or low).
53+
This is useful for connecting something such as a micro-switch.
5354

5455
``` python
55-
robot.arduino.pins[4].mode = GPIOPinMode.DIGITAL_INPUT
56+
robot.arduino.pins[4].mode = GPIOPinMode.INPUT
5657

57-
pin_value = robot.arduino.pins[4].digital_state
58+
pin_value = robot.arduino.pins[4].digital_value
5859
```
5960

60-
### `GPIOPinMode.DIGITAL_INPUT_PULLUP`
61-
62-
Same as `GPIOPinMode.DIGITAL_INPUT`, but with an internal [pull-up
63-
resistor](https://learn.sparkfun.com/tutorials/pull-up-resistors)
64-
enabled.
61+
Some external switches may require a pull up resistor.
62+
`GPIOPinMode.INPUT_PULLUP`, is the same as `INPUT` but also enables an internal [pull-up
63+
resistor](https://learn.sparkfun.com/tutorials/pull-up-resistors).
6564

6665
``` python
67-
robot.arduino.pins[4].mode = GPIOPinMode.DIGITAL_INPUT_PULLUP
66+
robot.arduino.pins[4].mode = GPIOPinMode.INPUT_PULLUP
6867

69-
pin_value = robot.arduino.pins[4].digital_state
68+
pin_value = robot.arduino.pins[4].digital_value
7069
```
7170

72-
### `GPIOPinMode.DIGITAL_OUTPUT`
71+
### Digital Output
7372

74-
In this mode, we can set binary values of `0V` or `5V` to the pin.
73+
Digital outputs can be used to set binary values of `0V` or `5V` to the pin.
74+
This can be used to turn an LED on and off for example.
7575

7676
``` python
77-
robot.arduino.pins[4].mode = GPIOPinMode.DIGITAL_OUTPUT
78-
robot.arduino.pins[6].mode = GPIOPinMode.DIGITAL_OUTPUT
77+
robot.arduino.pins[4].mode = GPIOPinMode.OUTPUT
78+
robot.arduino.pins[6].mode = GPIOPinMode.OUTPUT
7979

80-
robot.arduino.pins[4].digital_state = True
81-
robot.arduino.pins[6].digital_state = False
80+
robot.arduino.pins[4].digital_value = True
81+
robot.arduino.pins[6].digital_value = False
8282
```
8383

84-
### `GPIOPinMode.ANALOGUE_INPUT`
84+
### Analog Input
8585

86-
Certain sensors output analogue signals rather than digital ones, and so
87-
have to be read differently. The Arduino has six analogue inputs, which
88-
are labelled `A0` to `A5`; however pins `A4` and `A5` are reserved and
89-
cannot be used.
86+
Certain sensors output analog signals rather than digital ones, and so
87+
have to be read differently. The Arduino has six analog inputs, which
88+
are labelled `A0` to `A5`.
9089

9190
!!! tip
92-
Analogue signals can have any voltage, while digital signals can only
93-
take on one of two voltages. You can read more about digital vs analogue
91+
Analog signals can have any voltage, while digital signals can only
92+
take on one of two voltages. You can read more about digital vs analog
9493
signals [here](https://learn.sparkfun.com/tutorials/analog-vs-digital).
9594

9695
``` python
97-
from sbot import AnaloguePin
96+
from sbot import AnalogPins
9897

99-
robot.arduino.pins[AnaloguePin.A0].mode = GPIOPinMode.ANALOGUE_INPUT
98+
robot.arduino.pins[AnalogPins.A0].mode = GPIOPinMode.INPUT
10099

101-
pin_value = robot.arduino.pins[AnaloguePin.A0].analogue_value
100+
pin_value = robot.arduino.pins[AnalogPins.A0].analog_value
102101
```
103102

104103
!!! tip
105-
The values are the voltages read on the pins, between 0 and 5.
104+
The values are the voltages read on the pin, between 0 and 5.
106105

107106
## Ultrasound Sensors
108107

109-
You can also measure distance using an ultrasound sensor from the arduino.
108+
You can also measure distance using an ultrasound sensor from the arduino. Ultrasound sensors return the distance of the closest object in mm.
110109

111110
```python
112111
# Trigger pin: 4
113112
# Echo pin: 5
114113

115-
distance_metres = robot.arduino.ultrasound_measure(4, 5)
114+
distance_mm = robot.arduino.ultrasound_measure(4, 5)
116115
```
117116

118117
!!! warning
119-
The ultrasound sensor can measure distances up to 2 metres. If the ultrasound signal has to travel further than 2m, the sensor will timeout and return `None`.
118+
The ultrasound sensor can measure distances up to 4 metres.
119+
If the ultrasound signal has to travel further than 4m, the sensor will timeout and return 0.

0 commit comments

Comments
 (0)