dmrlawson.co.uk - dmrlawson – Electronics and coding

Example domain paragraphs

Before learning about the DSHOT protocol my plan was to try writing the flight controller in Python. My main reason for this is that I’m hoping to use the Raspberry Pi’s Sense HAT for its gyroscope and other sensors to stabilise the quadcopter. The Sense HAT has its own Python module, making it very easy to read from the sensors.

Initially I did have a quick go at implementing DSHOT in Python, though I didn’t expect it to work.

import RPi.GPIO as GPIO import time import gc # Hopefully reduce interruptions gc.disable() ESC_PIN = 19 # DSHOT150 TIMINGS (6.68us per frame) T0H = 0.00000250 # T0H = 2500ns T0L = 0.00000418 # T0L = 4180ns T1H = 0.00000500 # T1H = 5000ns T1L = 0.00000168 # T1L = 1680ns INTER_PACKET_DELAY = 0.00002 # 20us def transmit_one(): GPIO.output(ESC_PIN, GPIO.HIGH) time.sleep(T1H) GPIO.output(ESC_PIN, GPIO.LOW) time.sleep(T1L) def transmit_zero(): GPIO.output(ESC_PIN, GPIO.HIGH) time.sleep(T0H) GPIO.output(ESC_PIN,