From d75f0030208439890f8174e00fdfd09670eac32f Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Thu, 29 Oct 2026 17:41:09 -0400 Subject: [PATCH] updating schedule --- Readme.md | 28 ++++++++++- week6/resources/serial_mqtt_example.py | 64 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 2af791c..2cc2755 100644 --- a/Readme.md +++ b/Readme.md @@ -120,7 +120,31 @@ Concepts Covered: **Project Pt 1:** Create your first custom printed circuit board. Learn to design for custom components and create a PCB that will print successfully with a PCB vendor. These boards will be assembled in week 6. --- -## Week 5 - Internet of Things +## Week 5 - Motor Control + +Learn the differences between motors and get them moving using a variety of techniques. + + +* Principles of DC motors +* Simple motor movement - voltage and amperage +* Two channel controllers +* Controllers with external power supply +* Servo motors - continuous and 180 degree +* Basic gearing and mechanical + + +Concepts Covered: + +* Magnets and stators +* PWM speed control +* Control signals and power supplies +* Calculating angles for servo motors +* Steps and gear ratios + +**Project** Examine all aspects of motor control using a variety of control boards. Have the rpi Pico control motors. + +--- +## Week 6 - Internet of Things Returning to our Single Board Computer/Microcontroller pair, we learn the basics of connecting to networks and expanding our device communications. @@ -144,7 +168,7 @@ Concepts Covered: --- -## Week 6 - Demo Scene +## Bonus Week - Demo Scene Assemble your custom-made PCB into a working, powered circuit. Combine your skills to connect it locally and to the internet. diff --git a/week6/resources/serial_mqtt_example.py b/week6/resources/serial_mqtt_example.py index e69de29..7fe30e0 100644 --- a/week6/resources/serial_mqtt_example.py +++ b/week6/resources/serial_mqtt_example.py @@ -0,0 +1,64 @@ +import time +import paho.mqtt.client as mqtt +import serial + +# Configuration +SERIAL_PORT = '/dev/ttyAMA0' # Adjust for your system (e.g., 'COM3' on Windows) +BAUD_RATE = 9600 +MQTT_BROKER = "localhost" # Public test broker +MQTT_PORT = 1883 +MQTT_TOPIC = "python/mqtt/test" + +def main(): + # 1. Initialize Serial Connection + try: + ser = serial.Serial( + port=SERIAL_PORT, + baudrate=BAUD_RATE, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + timeout=1 + ) + except serial.SerialException as e: + print(f"Could not open serial port: {e}") + return + + # 2. Initialize MQTT Client + client = mqtt.Client() + + # Optional: Add callbacks for connection status + def on_connect(client, userdata, flags, reason_code, properties): + if reason_code == 0: + print("Connected to MQTT Broker") + else: + print(f"Failed to connect, return code {reason_code}") + + client.on_connect = on_connect + client.connect(MQTT_BROKER, MQTT_PORT, 60) + + # 3. Read Serial and Publish to MQTT + print("Reading from serial port and publishing to MQTT...") + try: + for i in range(10): # Read 10 messages as an example + if ser.in_waiting > 0: + # Read line from serial port + data = ser.readline().decode('utf-8').strip() + if data: + # Publish to MQTT topic + client.publish(MQTT_TOPIC, data) + print(f"Published: {data}") + else: + print("No data available on serial port") + time.sleep(1) # Wait 1 second between reads + except KeyboardInterrupt: + print("Interrupted by user") + finally: + # Cleanup + ser.close() + client.disconnect() + client.loop_stop() + print("Disconnected and closed serial port.") + +if __name__ == "__main__": + main() \ No newline at end of file