Programming With Firmata Protocol - MEDIATEK LinkIt Smart 7688 Developer's Manual

Hide thumbs Also See for LinkIt Smart 7688:
Table of Contents

Advertisement

global s
# open serial COM port to /dev/ttyS0, which maps to UART0(D0/D1)
# the baudrate is set to 57600 and should be the same as the one
# specified in the Arduino sketch uploaded to ATmega32U4.
s = serial.Serial("/dev/ttyS0", 57600)
def loop():
# send "1" to the Arduino sketch on ATmega32U4.
# the sketch will turn on the LED attached to D13 on the board
s.write("1")
time.sleep(1)
# send "0" to the sketch to turn off the LED
s.write("0")
time.sleep(1)
if __name__ == '__main__':
setup()
while True:
loop()
Execute this Python program in the system console – this program basically writes string
2)
"1" and "0" to the /dev/ttyS0 port which maps to Serial1 interface in Arduino. The Arduino
sketch that was uploaded in the previous section will receive the string and then blink the
on-board LED accordingly.
You can now extend the Arduino sketch to drive other devices such as PWM, I2C devices and
synchronize the states by extending the command messages between Arduino and the Linux side.
If a large amount of peripheral types need to be included, you may want to use some external
libraries to implement the communication protocol. One of such protocol – Firmata is described
in the following section.

6.6. Programming with Firmata Protocol

This section demonstrates how to establish communication between the MPU and the MCU over
serial port using Firmata protocol. There are several Firmata implementations using different
interfaces such as pyFirmata and PyMata, which is programmed in Python; other languages
including node.js and
cylon.js
6.6.1.
Python examples
Two examples are provided in Python in the following sections to demonstrate how to use the
Firmata protocol: pyFirmata and PyMata interfaces.
The Serial ports on the microcontrollers are designated as shown in
MCU
In Arduino
Corresponding Pins
Table 18 Serial Pin Mapping Between MPU and MCU
This document contains information that is proprietary to MediaTek Inc.
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
MediaTek LinkIt™ Smart 7688 Developer's Guide
examples are provided as well in the next sections.
Serial1
D0 and D1
© 2015, 2016 MediaTek Inc.
Table
MPU
In Linux
Pin MUX
18:
/dev/ttyS0
UART0 (GPIO12 and
GPIO13)
Page 78

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents