albertaloop / T_SWE_2022_2023

Software for AlbertaLoop's first-generation pod.
MIT License
3 stars 0 forks source link

Test UDP Communication on Teensy 4.1 #12

Closed Iyury1 closed 1 year ago

Iyury1 commented 2 years ago

Summary

We will need to communicate over a UDP connection between a Python application connected to our GUI, and a C++ program running on a Teensy 4.1. The Python application is being tested in issue #11 .

We can either make the Teensy 4.1 the UDP server with the Python application the UDP client, or we could make the Teensy a UDP client with the Python application acting as the server. Previously we have used the Teensy as the UDP server.

For examples of a Teensy UDP server, we can look at code from a previous member written for the Teensy 3.6: https://github.com/albertaloop/T_SWE_2019_2020/blob/cody-obc/Firmware/obc/src/main.cpp https://github.com/albertaloop/T_SWE_2019_2020/blob/cody-pod-telemetry-program/pod_telemetry_program/main.cpp

There is also a previous issue that was opened on the old repo which links to examples for the 4.1 along with instructions: issue #59 The webserver example provided in that issue is found here: https://github.com/vjmuzik/NativeEthernet/tree/master/examples/WebServer Also there are instructions for finding the Teeny's MAC address here: https://forum.pjrc.com/threads/62932-Teensy-4-1-MAC-Address The webserver example is for Ethernet communication over port 80, which is used for HTTP applications. We will need to use a different port for UDP communication, and we may need to use a UDP specific library, although I am not 100% sure.

There are examples of Teensy 4.1 UDP servers mentioned in these forum posts, which may be helpful: https://forum.pjrc.com/threads/64253-Teensy-4-1-UDP-and-web-server-drop-packets https://forum.pjrc.com/threads/60857-T4-1-Ethernet-Library/page4

Connecting to remote Pi server to program Teeny's remotely

The first thing that is required for remote development is to download the University Cisco AnyConnect VPN, and use SSH to access the Rasperry Pi at school by follow the instructions here: https://docs.google.com/document/d/1TL32blBIJVRt870pOVqz_mUF7cOXglUmwXIvYclUewg/edit?usp=sharing

Next, you will have to follow the instructions for remote firmware programming here: https://docs.google.com/document/d/1lr8_rNuS0BvXKBEfrXjV6XQpJPV_akC-iO6kcPvfseE/edit?usp=sharing

After opening a terminal on the Pi using SSH, you can check which devices are connected by typing: "picocom -b 9600 /dev/serial/by-id/" and pressing tab a few times. Note: the actual baud rate you use is dependent on the Serial object created in the Teensy program running.

The two devices currently listed are:

usb-Teensyduino_USB_Serial_11602960-if00 usb-Teensyduino_USB_Serial_11603020-if00

The device connected to the Pi is usb-Teensyduino_USB_Serial_11603020-if00. You can check which hardware is connected to a device from this spreadsheet: https://docs.google.com/spreadsheets/d/1-ZlJaabliIlsx-5mY10GtOopHvoOPvqwuj2UHnMoZSU/edit?usp=sharing

Follow the instructions in the "local development" section of the "Programming Teensies Locally and Remotely" document. When you build a Teensy project in platform io, the firmware.hex file will be located within your project directory in ".pio/build/teensy41/firmware.hex"

To upload your hex file to the Pi. Open a terminal on your computer and enter the following command: "scp pi@129.128.214.121:/tmp" image

Then open a terminal of the Pi using SSH. Upload your hex file to the Teensy with the command: "tycmd upload --board 11603020 /tmp/" image

Test your program by opening a serial connection with: "picocom -b 9600 /dev/serial/by-id/usb-Teensyduino_USB_Serial_11603020-if00"

Acceptance Criteria