0% found this document useful (0 votes)
21 views13 pages

Cansat Wireless Transmission Proposal

This document provides a detailed guide on how to send data wirelessly using XBee modules and a Raspberry Pi Pico. It includes a list of required components, setup instructions, and coding examples for both the transmitter and receiver. Additionally, it offers troubleshooting tips and references for further learning on the topic.

Uploaded by

nataliedavies150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views13 pages

Cansat Wireless Transmission Proposal

This document provides a detailed guide on how to send data wirelessly using XBee modules and a Raspberry Pi Pico. It includes a list of required components, setup instructions, and coding examples for both the transmitter and receiver. Additionally, it offers troubleshooting tips and references for further learning on the topic.

Uploaded by

nataliedavies150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

How to send data wirelessly – by Andrew Wong 🤓🤓

Components:
Using XBee: (It looks like this )

Full name: Zigbee XBee Module S2C 802.15.4 2mV with Wire Antenna XB24CZ7WIT-004

Link: Amazon | AliExpress

STATSSS!!

Adapter must be used to connect to breadboard

XBee USB Adapter (UART communication board) (It looks like this )

Operates with 3.3V logic <— if that helps

Link: Amazon | AliExpress

It looks like this when they are combined:

Components Required:

Raspberry Pi Pico x1 (potentially 2*)

XBee Module x2

XBee Adapter x2

SD Card and SD card reader


*The reason why we need two is: one for sending and one for receiving, but I don’t think
that will be necessary

Setting up of the modules:


Need to download software called XCTU

Download link:

It should look like this after you have downloaded

Configuring the modules:

Firstly, the “Coordinator”

1. Connect the XBee module to computer via USB


2. Open the XCTU software
3. Press on discover radio devices icon
4. Select the correct USB port when prompted

5. Press next
6. Press finish

7. Then it will search for radio modules

8. Click add selected devices


9. It should then look like this, press on the device on the left

10. Press on the update icon to update firmware

11. Change PAN ID to around 1001-1020


12. Change CE Coordinator Enable to Coordinator [1]

13. Change API enabled to “API Enabled [1]”

14. Click on “write” to save changes

15. Repeat all the steps for the second XBee, but for step 12, change to End Device
instead, make sure both XBee have the same PAN ID, also for steps 13 and 14,
Change AP API Enable to “API Enabled with escaping [2]” and also change JV
channel verification to “Enabled[1]”

Connecting transmitters to Raspberry Pi:


Transmitter Circuit (End Device)
Connect the XBee Module Adapter VCC & GND Pin to 5V & GND Pin of the Pico. For the
TX & RX part of the XBee Module Adapter, we will use the UART0 Pin of the Pico.

Should look something like this:

Receiver Circuit (Coordinator)

I don’t think we will need a second Raspberry Pico for this, though many examples
online point towards the XBee having to be connected to a separate Raspberry Pico, I
somehow don’t think that would be necessary as little computation is required on the
receiving end. Also the receiving XBee will only be required to be connected to the
computer for it to work I think

However, this is the information if connection with a separate Raspberry Pico is


required.
Connect the XBee Module Adapter’s VCC and GND pins to the 5V and GND pins on the
Raspberry Pi Pico, for data communication, connect the XBee Module Adapter’s TX and
RX pins to the Raspberry Pi Pico’s UART0 pins (TX to RX and RX to TX)

Connecting SD cards to Raspberry Pi (optional)


It is good to keep in mind that storing data is not the fundamental part of the
competition, and that transmission is required as a spec point.

Need for adapter

Link

SD Card should be formatted with the FAT32 file system to be compatible with uos
module in MicroPython

Steps:

1. Insert SD Card into computer


2. Open File Explorer and right click on SD Card
3. Select “Format”
4. Choose FAT32 as the file system
5. Click “Start” to format the card

Download sdcard.py file to your computer from GitHub 🤡

1. Open Thonny IDE.


2. Connect your Raspberry Pi Pico to your computer using a USB cable.
3. In Thonny, open the downloaded sdcard.py file.
4. Save the file to the Pico by selecting File > Save As…, then choose the Raspberry Pi
Pico as the location and save it as sdcard.py in the root directory.

Wire the SD card adapter as follows:

CS (Chip Select): Gp9 (Pin 12)

SCK(Clock): GP10 (Pin 14)

MOSI (Master Out Slave In): GP 11 (Pin 15)

MISO (Master In Slave Out): GP8 (Pin 11)

VCC: 3.3V

GND: GND

Coding (to be placed in Thonny)


Disclaimer: the code is just for reference only!! I’m sorry if its
horrendous…

Transmitter Code (End Device)

import machine
import utime
import dht
import sdcard
import uos
from machine import UART

# Assign chip select (CS) pin (and start it high)


cs = machine.Pin(9, machine.Pin.OUT) # GP9 (Pin 12)
# Initialise SPI peripheral (start with 1 MHz)
spi = machine.SPI(1,
baudrate=1000000, # 1 MHz
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(10), # GP10 (Pin 14)
mosi=machine.Pin(11), # GP11 (Pin 15)
miso=machine.Pin(8)) # GP8 (Pin 11)

# Initialise SD card
sd = sdcard.SDCard(spi, cs)

# Mount filesystem
vfs = uos.VfsFat(sd)
uos.mount(vfs, "/sd")

# Sample initialisation of the sensor (dht in this case)


sensor = dht.DHT11(machine.Pin(15))

# Initialise UART for XBee communication


uart = UART(0, baudrate=9600)

# Sample code from sensor


def read_and_send():
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()

# Prepare the message string


message = "<T:{},H:{}>".format(temp, hum)

# Send the message over UART


uart.write(message)

# Debugging output to console


print("Sent Temp: {} C, Hum: {} %".format(temp, hum))

# Create file if first time running


if first:
with open("/sd/Data.txt", "w") as file:
file.write("")
first = not first

# Open created file on the SD card and write data to it


with open("/sd/Data.txt", "a") as file:
file.write(message+"\n")
except OSError as e:
print("Failed to read from sensor")

utime.sleep(2)

first = True
while True:
read_and_send()
import machine
import utime
import dht
import sdcard
import uos
from machine import UART

# Assign chip select (CS) pin (and start it high)


cs = machine.Pin(9, machine.Pin.OUT) # GP9 (Pin 12)

# Initialise SPI peripheral (start with 1 MHz)


spi = machine.SPI(1,
baudrate=1000000, # 1 MHz
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(10), # GP10 (Pin 14)
mosi=machine.Pin(11), # GP11 (Pin 15)
miso=machine.Pin(8)) # GP8 (Pin 11)

# Initialise SD card
sd = sdcard.SDCard(spi, cs)

# Mount filesystem
vfs = uos.VfsFat(sd)
uos.mount(vfs, "/sd")

# Sample initialisation of the sensor (dht in this case)


sensor = dht.DHT11(machine.Pin(15))

# Initialise UART for XBee communication


uart = UART(0, baudrate=9600)

# Sample code from sensor


def read_and_send():
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()

# Prepare the message string


message = "<T:{},H:{}>".format(temp, hum)
# Send the message over UART
uart.write(message)

# Debugging output to console


print("Sent Temp: {} C, Hum: {} %".format(temp, hum))

# Create file if first time running


if first:
with open("/sd/Data.txt", "w") as file:
file.write("")
first = not first

# Open created file on the SD card and write data to it


with open("/sd/Data.txt", "a") as file:
file.write(message+"\n")

except OSError as e:
print("Failed to read from sensor")

utime.sleep(2)

first = True
while True:
read_and_send()

Receiver Code (Coordinator) (Only if connected with another Raspberry Pico)

from machine import UART


import utime
import sdcard
import uos

# Initialise UART for XBee communication


uart = UART(0, baudrate=9600)

# Sample code from sensors


def receive_and_display():
if uart.any():
message = uart.readline().decode()
if message.startswith('<') and message.endswith('>'):
print("Raw Msg: ", message.strip())

# Extract temperature and humidity


try:
temp_start = message.find('T:') + 2
temp_end = message.find(',', temp_start)
temp = float(message[temp_start:temp_end])

hum_start = message.find('H:') + 2
hum_end = message.find('>', hum_start)
hum = float(message[hum_start:hum_end])

# Debugging output to console


print("Received Temp: {} C, Hum: {} %".format(temp, hum))
except ValueError:
print("Failed to parse temp and humidity.")

# View contents of SD card


def view_sdcard():
# Open the file we just created and read from it
with open("/sd/Data.txt", "r") as file:
data = file.read()
print(data)

while True:
receive_and_display()
utime.sleep(1) # Small delay to prevent flooding the output
view_sdcard()

How it is going to work:


The code on the Raspberry Pico will tell the sensors to send data to the End Device. The
End Device will then send the data with the code “uart.write()” (python) or
“xbeePort.WriteLine()” (C#) or “xbeePort.WriteBytes()” (Java?). These are just
suggestions, there are other options as well. The code will then be loaded onto the Pico.
The code will be run, and data would be sent over to the Coordinator. The data can be
viewed through the same XCTU software by pressing this icon

Press here to create a new frame and set the destination address to the MAC address of
the receiver (Coordinator). Also press this button so that the icon looks like this

When all that’s done, the data “should be” able to be sent remotely.

Hi!!! Welcome to the end of the document. If you think


something is wrong here – it probably is! (I am so sorry!)
Please do not hesitate to
scrutinise anything on here.
Also, if the two XBees fail to
connect, it is most likely due to
some settings not yet configured, if that becomes an issue, I will look at more YouTube
videos on how others have done it and see if they have tweaked with some settings we
haven’t and we shall tweak them. Also, technically, online sources point to both XBees
being able to send data to each other regardless of which type it is, but we shall see
which one of ours send and which one of ours receives and determine which one is to be
placed in the cansat and get concussion and which one is to be connected to a computer
safely on the ground

References:
Here’s when you realise most of the stuff on here is copied word to word from the
following websites:

https://how2electronics.com/interfacing-xbee-module-with-
raspberry-pi-pico-micropython/

https://circuitdigest.com/microcontroller-projects/raspberry-
pi-xbee-module-interfacing

https://learn.sparkfun.com/tutorials/exploring-xbees-and-xctu/all

https://medium.com/@marcj_40686/using-an-sd-card-with-the-raspberry-pi-pico-for-
data-storage-in-micropython-da9c8264c04c

YT Vids for XBee configuration

https://www.youtube.com/watch?v=FGmQHSfUPBU

https://www.youtube.com/watch?v=crjv9021Dxk

https://www.youtube.com/watch?v=mIBq0KLqWLA
Mysterious Link

You might also like