Пример #1
0
 def print(self, text, gui=False):
     try:
         if text:
             if gui:
                 gui.set_data_str(text)
             self.board.send_sysex(STRING_DATA,
                                   util.str_to_two_byte_iter(text))
     except TypeError:
         self.board.send_sysex(STRING_DATA,
                               util.str_to_two_byte_iter('Error'))
Пример #2
0
    def test_handle_report_firmware(self):

        self.assertEqual(self.board.firmware, None)
        data = list(self.FIRMWARE_VERSION) + str_to_two_byte_iter(self.FIRMWARE_NAME)
        self.board._handle_report_firmware(*data)
        self.assertEqual(self.board.firmware, self.FIRMWARE_NAME)
        self.assertEqual(self.board.firmware_version, self.FIRMWARE_VERSION)
Пример #3
0
 def test_handle_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     data = bytearray([2, 1])
     data.extend(str_to_two_byte_iter('Firmware_name'))
     self.board._handle_report_firmware(*data)
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #4
0
 def test_handle_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     data = bytearray([2, 1])
     data.extend(str_to_two_byte_iter('Firmware_name'))
     self.board._handle_report_firmware(*data)
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #5
0
    def test_handle_report_firmware(self):

        self.assertEqual(self.board.firmware, None)
        data = list(self.FIRMWARE_VERSION) + str_to_two_byte_iter(
            self.FIRMWARE_NAME)
        self.board._handle_report_firmware(*data)
        self.assertEqual(self.board.firmware, self.FIRMWARE_NAME)
        self.assertEqual(self.board.firmware_version, self.FIRMWARE_VERSION)
Пример #6
0
    def write_to_lcd(self, *args):
        message = ''
        for arg in args:
            message += str(arg)

        print(message)
        self.arduino.send_sysex(STRING_DATA,
                                util.str_to_two_byte_iter(str(message)))
Пример #7
0
 def test_incoming_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [chr(pyfirmata.START_SYSEX),
            chr(pyfirmata.REPORT_FIRMWARE),
            chr(2),
            chr(1)] + str_to_two_byte_iter('Firmware_name') + \
           [chr(pyfirmata.END_SYSEX)]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #8
0
 def test_incoming_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [pyfirmata.START_SYSEX,
            pyfirmata.REPORT_FIRMWARE,
            2,
            1] + list(str_to_two_byte_iter('Firmware_name')) + \
           [pyfirmata.END_SYSEX]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #9
0
 def test_incoming_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [chr(pyfirmata.START_SYSEX),
            chr(pyfirmata.REPORT_FIRMWARE),
            chr(2),
            chr(1)] + str_to_two_byte_iter('Firmware_name') + \
           [chr(pyfirmata.END_SYSEX)]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #10
0
 def test_incoming_report_firmware(self):
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [pyfirmata.START_SYSEX,
            pyfirmata.REPORT_FIRMWARE,
            2,
            1] + list(str_to_two_byte_iter('Firmware_name')) + \
           [pyfirmata.END_SYSEX]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, 'Firmware_name')
     self.assertEqual(self.board.firmware_version, (2, 1))
Пример #11
0
 def test_incoming_report_firmware(self):
     n1, n2 = self.FIRMWARE_VERSION
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [chr(pyfirmata.START_SYSEX),
            chr(pyfirmata.REPORT_FIRMWARE),
            chr(n1),
            chr(n2)] + str_to_two_byte_iter(self.FIRMWARE_NAME) + \
           [chr(pyfirmata.END_SYSEX)]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, self.FIRMWARE_NAME)
     self.assertEqual(self.board.firmware_version, self.FIRMWARE_VERSION)
Пример #12
0
 def test_incoming_report_firmware(self):
     n1, n2 = self.FIRMWARE_VERSION
     self.assertEqual(self.board.firmware, None)
     self.assertEqual(self.board.firmware_version, None)
     msg = [chr(pyfirmata.START_SYSEX),
            chr(pyfirmata.REPORT_FIRMWARE),
            chr(n1),
            chr(n2)] + str_to_two_byte_iter(self.FIRMWARE_NAME) + \
           [chr(pyfirmata.END_SYSEX)]
     self.board.sp.write(msg)
     self.board.iterate()
     self.assertEqual(self.board.firmware, self.FIRMWARE_NAME)
     self.assertEqual(self.board.firmware_version, self.FIRMWARE_VERSION)
Пример #13
0
def write_loop(board):


    i = 0

    while True:

        message = util.str_to_two_byte_iter("Hi This is GhostRider")  # Converting String two midi format, 1 character of this string is as two bytes
        #message = "Hello yo"
        board.send_sysex(pyfirmata.pyfirmata.STRING_DATA, message)   # first argument is command and the secon is the data
        time.sleep(0.5)
        i=i+1
        print(i)
Пример #14
0
def incoming_sms():
    
    # get the message sent to the Twilio number
    body = request.values.get('Body', None)

    # create a response
    resp = MessagingResponse()
    resp.message("Message recieved!")
    
    # display message on lcd 
    board.send_sysex(STRING_DATA, util.str_to_two_byte_iter(body)) 

    print("Message body: " + str(body))
    print("Displayed on LCD screen!")

    return str(resp) # return the response
Пример #15
0
    def sendString(self, string: str) -> None:
        '''
            Отправить ASCII-совместимую строку на Arduino (никаких 
            символов Юникода!)

            Отправка строковых команд Arduino-исполнителям производится
            в том случае, если необходимо, чтобы исполнитель выполнл ка-
            кую-то ФУНКЦИЮ в своём коде со своей стороны и послал ответ.
            Например, поддержка цифровых датчиков была реализована имен-
            но по такому принципу.

            :param 'string': str
                Строка, которую необходимо отправить

            :returns: None
            '''
        self.send_sysex(0x71, ArduinoUtil.str_to_two_byte_iter(string))
        sleep(2)
def write_loop(board):

	msg_list = []
	msg_list.append("H")
	msg_list.append("W")
	msg_list.append("A")
	msg_list.append("Q")
	msg_list.append("T")

	i = 0

	while True:
	
		message = util.str_to_two_byte_iter("Hello yo")
		message = "Hello yo"	
		board.send_sysex(pyfirmata.pyfirmata.STRING_DATA, message)

		i += 1
		
		if i >= len(msg_list):
			i = 0

		time.sleep(0.5)
Пример #17
0
def lcdprint(text):
    if (text):
        board.send_sysex(STRING_DATA, util.str_to_two_byte_iter(text))
    else:
        lcdprint(" ")
Пример #18
0
import pyfirmata  #facilitates communication with Arduino https://pyfirmata.readthedocs.io/en/latest/
import numpy as np
from time import sleep
from pyfirmata import Arduino, util, STRING_DATA

try:
    portName = 'COM3'  #assigns a variable
    arduino = pyfirmata.Arduino(portName)  #creates an instance of a class
    it = pyfirmata.util.Iterator(arduino)
    it.start()  #calls a start method

    #Connect to arduino hardware on input port.
    input_pin = arduino.get_pin('a:0:i')  #analog, input to the computer
    sleep(1)

    Vout = input_pin.read()
    print(Vout * 5, 'Vout')
    arduino.send_sysex(STRING_DATA,
                       util.str_to_two_byte_iter(str(Vout * 5) + str(' Vout')))

finally:
    arduino.exit()
Пример #19
0
def send_string(msg):
    print('sending')
    board.send_sysex(0x71, util.str_to_two_byte_iter(msg+'\0'))
Пример #20
0
 def test_str_to_two_byte_iter(self):
     string, itr = 'StandardFirmata', bytearray()
     for i in string:
         itr.append(ord(i))
         itr.append(0)
     self.assertEqual(itr, str_to_two_byte_iter(string))
Пример #21
0
from pyfirmata import Board, util, boards
from random import randint
import math

PORT = '/dev/cu.usbmodem1411'


def test_handle(*data):
	print list(data[::2])

b = Board(PORT, boards.BOARDS['arduino'], 57600)
b.add_cmd_handler(0x71, test_handle)

random_strings = []
for i in xrange(10):
	r = map(lambda x: randint(0, 127), xrange(8))]
	print r
	s = ''.join(map(lambda x: chr(x), r))
	b.send_sysex(0x71, util.str_to_two_byte_iter(s))

print '================='

b.pass_time(2)

while b.bytes_available():
	b.iterate()
Пример #22
0
 def test_str_to_two_byte_iter(self):
     string, itr = 'StandardFirmata', bytearray()
     for i in string:
         itr.append(ord(i))
         itr.append(0)
     self.assertEqual(itr, str_to_two_byte_iter(string))
Пример #23
0
from pyfirmata import Arduino, util
import msvcrt

speed = 5
initial_angle = 90
board = Arduino('COM11')

print("press left or right arros to move the servo:")
print("press e to terminate the program:")
data = initial_angle
while True:
    c = ord(msvcrt.getch())
    if c != 224:
        if c == 101:
            print("program terminated.")
            break
            print()
        if c == 75:
            data -= speed
            if data < 0:
                data = 0
        if c == 77:
            data += speed
            if data > 180:
                data = 180
        board.send_sysex(0x71, util.str_to_two_byte_iter(f"{data}\0"))
Пример #24
0
def escrever(placa, col, lin, texto):
    dados = str(col) + ';' + str(lin) + ';' + texto
    if dados:
        placa.send_sysex(STRING_DATA, util.str_to_two_byte_iter(dados))
Пример #25
0
def msg(text):
    if text:
        board.send_sysex(STRING_DATA, util.str_to_two_byte_iter(text))
Пример #26
0
from pyfirmata import Arduino, util, STRING_DATA
board = Arduino('COM6')
board.send_sysex(STRING_DATA, util.str_to_two_byte_iter('Hello!'))


def msg(text):
    if text:
        board.send_sysex(STRING_DATA, util.str_to_two_byte_iter(text))