Skip to content

Commit 14bd8e1

Browse files
SWotomikewadsten
andauthored
samples/adc_polling: Update README.md to reference AV; use AV in sample
* Update main.py Read and use ADC Reference value to calculate the voltage value * Update README.md * Update samples/adc_polling/README.md improved item 2 Co-authored-by: Mike Wadsten <mikewadsten@gmail.com> * Update samples/adc_polling/main.py Co-authored-by: Mike Wadsten <mikewadsten@gmail.com> Co-authored-by: Mike Wadsten <mikewadsten@gmail.com>
1 parent 6626aeb commit 14bd8e1

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

samples/adc_polling/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ Make sure the hardware is set up correctly:
2323

2424
1. Plug the XBee3 radio module into the XBee adapter and connect it to your
2525
computer's USB port.
26-
2. Connect a voltage variable source to the pin configured as ADC (light
26+
2. If using XBee 3 Zigbee, DigiMesh, or 802.15.4, ensure that the **AV** command
27+
(Analog Voltage Reference) is configured to an input range which matches your
28+
voltage source:
29+
30+
* 0 = 1.25 V
31+
* 1 = 2.5 V
32+
* 2 = VDD
33+
34+
If using XBee Cellular or XBee 3 Cellular, the analog reference voltage is 2.5V.
35+
3. Connect a voltage variable source to the pin configured as ADC (light
2736
sensor, temperature sensor, etc). For testing purposes we recommend using a
2837
potentiometer. Follow these steps to connect it:
2938

@@ -112,4 +121,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112121
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113122
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114123
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
115-
SOFTWARE.
124+
SOFTWARE.

samples/adc_polling/main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,35 @@
1919
# SOFTWARE.
2020

2121
from machine import ADC
22+
import xbee
2223
import time
2324

2425
# Pin D3 (AD3/DIO3)
2526
ADC_PIN_ID = "D3"
2627

28+
# ADC reference voltage
29+
AV_VALUES = {0: 1.25, 1: 2.5, 2: 3.3, None: 2.5}
2730

2831
print(" +-------------------------------------+")
2932
print(" | XBee MicroPython ADC Polling Sample |")
3033
print(" +-------------------------------------+\n")
3134

35+
# Read the module's Analog Digital Reference
36+
try:
37+
av = xbee.atcmd("AV")
38+
except KeyError:
39+
# Reference is set to 2.5 V on XBee 3 Cellular
40+
av = None
41+
reference = AV_VALUES[av]
42+
print("Configured Analog Digital Reference: AV:{}, {} V".format(av, reference))
43+
44+
3245
# Create an ADC object for pin DIO0/AD0.
3346
adc_pin = ADC(ADC_PIN_ID)
3447

3548
# Start reading the analog voltage value present at the pin.
3649
while True:
37-
print("- ADC value:", adc_pin.read())
50+
value = adc_pin.read()
51+
print("- ADC value:", value)
52+
print("- Analog voltage [V]:", value * reference / 4095)
3853
time.sleep(1)

0 commit comments

Comments
 (0)