Exemple #1
0
def	init() :

	uart.init( baudrate = 115200)

	tpl	= (
		music.BA_DING,
		music.JUMP_UP,
		music.JUMP_DOWN,
		music.POWER_UP,
		music.POWER_DOWN,
		music.BADDY,
		music.RINGTONE,
		music.WAWAWAWAA,
		music.PUNCHLINE,
		music.DADADADUM,
		music.CHASE,
		music.ENTERTAINER,
		music.PRELUDE,
		music.BIRTHDAY,
		music.WEDDING,
		music.FUNERAL,
		music.FUNK,
		music.BLUES,
		music.PYTHON,
		music.ODE,
		music.NYAN
	)

	return	tpl
Exemple #2
0
def init():
    uart.init(115200)
    ro.config(queue=6,
              address=0x75626972,
              channel=4,
              data_rate=ro.RATE_1MBIT,
              length=64)
    ro.on()
    ut.sleep_ms(100)
Exemple #3
0
    def connect_wifi(self, yourSSID,yourPASSWORD):
	#connect to WIFI
	uart.init(baudrate=9600, tx = pin0, rx = pin1)
	uart.write("\r")
	self.__readUntil(uart, '\r')
	uart.write("|2|1|", yourSSID, ",", yourPASSWORD, "|\r")
	self.__readUntil(uart, '3')
	ipadress = self.__readUntil(uart, '\r')
	uart.init(baudrate=115200)
	print(ipadress)
        return True
Exemple #4
0
def init():
    uart.init(baudrate=115200)
    radio.on()

    stdin = stdin_routine()
    stdin.send(None)
    receiver = radio_receive()
    receiver.send(None)
    sender = radio_send()
    sender.send(None)

    print('OK uBit online.')

    while True:
        data = uart.readall()
        if data:
            stdin.send(data)
        rdata = radio.receive()
        if rdata:
            receiver.send(rdata)
        sleep(10)
Exemple #5
0
 def temperature(self):
         try:
             uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=self.tx_pin, rx=self.rx_pin)
             sleep(1)
             uart.write(b'\x50')
             t = 0
             buf = bytearray(1)
             while not uart.any() and t < 1000:
                 t = t + 1
                 sleep(5)
             if t < 1000:
                 uart.readinto(buf, 1)
             uart.init(115200)
             return(buf[0] - 45)
         except Exception as exc:
             uart.init(115200)
             print_exception(exc)
Exemple #6
0
 def distance_mm(self):
     try:
         uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=self.tx_pin, rx=self.rx_pin)
         sleep(1)
         uart.write(b'\x55')
         t = 0
         buf = bytearray(2)
         while not uart.any() and t < 1000:
             t = t + 1
             sleep(5)
         if t < 1000:
             uart.readinto(buf, 2)
         uart.init(115200)
         dist = buf[0] * 256 + buf[1]
         if dist > 1100:
             dist = -1
         return dist
     except Exception as exc:
         uart.init(115200)
         print_exception(exc)
Exemple #7
0
from microbit import uart, display, Image, sleep
import radio

radio.config(group=199)
radio.on()
uart.init(baudrate=115200)

Waiting_Time = 0
Time_Out = 300  # Set Time Out 3 Seconds
count = 0

RDF_NO = 0
STATE = "Receive_Msg"
PREV_STATE = "Receive_Msg"

def Encode_Data(Message):

    Encoded_Msg = ""
    for Letter in Message:
        Letter_Num = ord(Letter)
        Encoded_Letter_Num = Letter_Num + 29
        Encoded_Msg += chr(Encoded_Letter_Num)
    return Encoded_Msg

def Decoded_Data(Encoded_Msg):

    Decoded_Msg = ""
    for Letter in Encoded_Msg:
        Letter_Num = ord(Letter)
        Decoded_Letter_Num = Letter_Num - 29
        Decoded_Msg += chr(Decoded_Letter_Num)
Exemple #8
0
 def __init__(self, tx, rx):
     uart.init(tx=tx, rx=rx, baudrate=9600)
Exemple #9
0
from microbit import uart, button_b, display, Image

uart.init(115200)  # serial baudrate

RED = b'R'
YELLOW = b'Y'
GREEN = b'G'
TRIGGER = b'T'
CLEAR = b'C'
UNKNOWN = b'U'

dim_value = 9  # value 1-9 for dimming the display

NEUTRAL = Image('00000:09090:00000:99999:00000:')

display.show(Image.GHOST / 9 * dim_value)

while True:
    if uart.any():
        data = uart.read()
        if RED in data:
            display.show(Image.SAD / 9 * dim_value)
        elif YELLOW in data:
            display.show(NEUTRAL / 9 * dim_value)
        elif GREEN in data:
            display.show(Image.HAPPY / 9 * dim_value)
        elif CLEAR in data:
            display.clear()
        elif UNKNOWN in data:
            display.show(Image("?") / 9 * dim_value)
Exemple #10
0
# -*- coding: utf-8 -*-
"""Read the radio messages and write them in the serial port.
"""

from microbit import display, sleep, uart
import radio

from data import DATA_LENGTH, PERIOD_MS

display.scroll("receiver")

radio.config(length=DATA_LENGTH)
radio.on()
uart.init(115200)

while True:
    data = radio.receive()
    if data:
        uart.write(data)
    sleep(PERIOD_MS)
Exemple #11
0
from microbit import button_a, sleep, uart, pin1, pin2
from microbit import display, Image


class BitOut(retune.Retuner):
    def output(self, mess):
        uart.write(bytes(mess))


midistream = BitOut()
display.show(Image.HAPPY)

while not button_a.was_pressed():
    sleep(30)

try:
    uart.init(31250, tx=pin2, rx=pin1)
    display.show(Image.NO)
    while not button_a.was_pressed():
        mess = uart.read(4)
        if mess:
            display.show(Image.MUSIC_CROTCHET)
            midistream.write(mess)
except Exception as e:
    midibit_fail = e
    raise
finally:
    uart.init(115200)

display.show(Image.YES)
Exemple #12
0
def	init() :

	uart.init( baudrate = 115200)

	uart.write( "Hello World !\r\n")

# wait for button A press before initializing the UART
# to allow uploading of new firmware
while True:
    if button_a.is_pressed():
        display.set_pixel(0, 0, 0)
        break

    display.set_pixel(0, 0, 5)
    sleep(100)
    display.set_pixel(0, 0, 0)
    sleep(100)

# Initialize UART for MIDI
uart.init(baudrate=31250)
midi = MidiOut(uart)

tune = program = 0
# send a PROGRAM CHANGE to set instrument to #0 (Grand Piano)
midi.program_change(program)
# set led on first 4 rows of display to indicate current tune (1-20)
display.set_pixel(program, 4, 5)
# set led on lowest row of display to indicate selected program (1-5)
display.set_pixel(program, 4, 5)

while True:
    if button_a.is_pressed() and button_b.is_pressed():
        # when both buttons are pressed, change to next program (instrument)
        display.set_pixel(program, 4, 0)
        program = (program+1) % len(PROGRAMS)

# wait for button A press before initializing the UART
# to allow uploading of new firmware
while True:
    if button_a.is_pressed():
        display.set_pixel(0, 0, 0)
        break

    display.set_pixel(0, 0, 5)
    sleep(100)
    display.set_pixel(0, 0, 0)
    sleep(100)

# Initialize UART for MIDI
uart.init(baudrate=31250)
midi = MidiOut(uart)

tune = program = 0
# send a PROGRAM CHANGE to set instrument to #0 (Grand Piano)
midi.program_change(program)
# set led on first 4 rows of display to indicate current tune (1-20)
display.set_pixel(program, 4, 5)
# set led on lowest row of display to indicate selected program (1-5)
display.set_pixel(program, 4, 5)

while True:
    if button_a.is_pressed() and button_b.is_pressed():
        # when both buttons are pressed, change to next program (instrument)
        display.set_pixel(program, 4, 0)
        program = (program + 1) % len(PROGRAMS)
# Shove accelerometer data through the uart.
from microbit import accelerometer, sleep, uart, pin0, pin1
uart.init(rx=pin0, tx=pin1)

while True:
    uart.write(
        bytes(','.join([str(v)
                        for v in accelerometer.get_values()]), 'ascii') + '\n')
    sleep(20000)
	while True:
		response = radio.receive()
		if response is not None:							# Some data received
			uart.write(response+"\n")						# Write received data with line break on serial bus
			if data_received == 0:
				display.clear()								# Clear Microbit LEDs
			if "," in response:								# "(x,y,z)" data received
				cy, cx = divmod(data_received, 5)
				display.set_pixel(cx, cy, 9)
				# Increase and limit data_received value within 0-24 range
				data_received = 0 if data_received >= 24 else data_received+1
			elif response == "done":
				data_received = 0
				display.show(Image.YES)
			elif response == "exit":
				display.show(Image.HAPPY)
				sleep(2000)
				display.clear()
				break
        else:
			sleep(100)

if __name__ == "__main__":
	try:
		uart.init(baudrate=115200, bits=8, parity=None, stop=1)
		radio.config(channel=CHANNEL, data_rate=radio.RATE_2MBIT, power=7, queue=150)
		radio.on()
		main()
	finally:
		uart.close()
		radio.off()
Exemple #17
0
        i2c.write(self.address, bytearray([0xFC, off & 0xFF]))
        i2c.write(self.address, bytearray([0xFD, off >> 8]))


def set_car_speed():
    pwm.set_pwm(12, 0, speed[0] * 16)
    pwm.set_pwm(13, 0, speed[1] * 16)
    pwm.set_pwm(14, 0, speed[2] * 16)
    pwm.set_pwm(15, 0, speed[3] * 16)


pwm = PCA9685(i2c)
for i in range(1, 6, 1):
    pwm.set_pwm(i, 0, 0)
speed = [0] * 4
uart.init(baudrate=115200, tx=pin12, rx=pin13)


def send_AT(mSend, mRec1, mRec2=b""):
    while True:
        uart.write(mSend)
        sleep(100)
        if uart.any():
            s = uart.readall()
            if s == mRec1 or s == mRec2:
                break
    display.show(Image.HAPPY)
    sleep(200)


display.show(['1'])