From e8dd3c3fe9254cc47f1d8d4656b1725c4222d4c5 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Wed, 30 Jun 2021 00:56:08 +0100 Subject: [PATCH] Copy in functioning tests from pi --- .../raspberry_pi/{ => tests}/servo_test.py | 0 .../raspberry_pi/tests/test_i2c.py | 35 +++++++++++++++++++ .../raspberry_pi/tests/test_tx.py | 12 +++++++ 3 files changed, 47 insertions(+) rename crawler_software/raspberry_pi/{ => tests}/servo_test.py (100%) create mode 100644 crawler_software/raspberry_pi/tests/test_i2c.py create mode 100644 crawler_software/raspberry_pi/tests/test_tx.py diff --git a/crawler_software/raspberry_pi/servo_test.py b/crawler_software/raspberry_pi/tests/servo_test.py similarity index 100% rename from crawler_software/raspberry_pi/servo_test.py rename to crawler_software/raspberry_pi/tests/servo_test.py diff --git a/crawler_software/raspberry_pi/tests/test_i2c.py b/crawler_software/raspberry_pi/tests/test_i2c.py new file mode 100644 index 0000000..49c84ca --- /dev/null +++ b/crawler_software/raspberry_pi/tests/test_i2c.py @@ -0,0 +1,35 @@ +# Raspberry Pi Master for Arduino Slave +# i2c_master_pi.py +# Connects to Arduino via I2C + +# DroneBot Workshop 2019 +# https://dronebotworkshop.com + +from smbus import SMBus +import time + +addr = 0x8 # bus address +bus = SMBus(1) # indicates /dev/ic2-1 + +numb = 1 + +print ("Enter num") + +for _x in range (0, 4): + for i in range(70, 130): + bus.write_byte(addr, i) + time.sleep(0.02) + for i in range(130, 70, -1): + bus.write_byte(addr, i) + time.sleep(0.02) + +#while numb == 1: +# +# ledstate = input(">>>> ") +# +# if ledstate == "1": +# bus.write_byte(addr, 0x1) # switch it on +# elif ledstate == "0": +# bus.write_byte(addr, 0x0) # switch it on +# else: +# numb = 0 diff --git a/crawler_software/raspberry_pi/tests/test_tx.py b/crawler_software/raspberry_pi/tests/test_tx.py new file mode 100644 index 0000000..747b9ed --- /dev/null +++ b/crawler_software/raspberry_pi/tests/test_tx.py @@ -0,0 +1,12 @@ +import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library +from time import sleep # Import the sleep function from the time module + +GPIO.setwarnings(False) # Ignore warning for now +GPIO.setmode(GPIO.BOARD) # Use physical pin numbering +GPIO.setup(12, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial value to low (off) + +while True: # Run forever + GPIO.output(12, GPIO.HIGH) # Turn on + sleep(1) # Sleep for 1 second + GPIO.output(12, GPIO.LOW) # Turn off + sleep(1) # Sleep for 1 second