Arduino Serial Interface Gui

Posted onby
Active4 months ago

I am trying to develop a GUI to control a device hooked up on the Arduino. The Arduino communicates with the device through SPI. I have developed a GUI on MATLAB to visualize read by the Arduino. For this, I made Arduino write data from the MISO line to the serial port and MATLAB would read from the same port and do its magic. However, I am trying to come up with a method to write to the MOSI line using the GUI.

Asynchronous serial interface
  • Arduino with Vb.net GUI control. Only Serial Communication Code lines and one Button example is uploaded her. Arduino Uno and Bluetooth Interface.
  • I need help figuring how to control an Arduino program using a Python GUI. This is my first project involving user-interface design and Arduino so I don't know where to start with this task.

Right now I am thinking of making Arduino listen for a particular code (like a character) on the serial port and once it sees it, it will look for an x number of succeeding bytes. The bytes will be formatted in a particular way so that Arduino can then parse it and write to the appropriate registers.

Is there a better way to do this? As a generic question, what's a good way to write to a device hooked onto a microcontroller using I2C or SPI through a GUI?

Mathews JohnMathews John

Instrumentino is an open-source modular graphical user interface framework for controlling Arduino based experimental instruments. It expands the control capability of Arduino by allowing instruments builders to easily create a custom user interface program running on an attached personal computer. I do realize that this is more of a Python tutorial than an Arduino tutorial. The GUI interface looks like this The buttons allow you to switch on or off a couple of LEDs and the slider allows you to move a servo. When the program starts it allows you to select the serial port for the Arduino. I have only tested this on Linux. The Arduino communicates with the device through SPI. I have developed a GUI on MATLAB to visualize read by the Arduino. For this, I made Arduino write data from the MISO line to the serial port and MATLAB would read from the same port and do its magic. However, I am trying to come up with a method to write to the MOSI line using the GUI.

migrated from electronics.stackexchange.comDec 18 '17 at 3:45

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

4 Answers

I grappled with the same question for a while. Here is how I solved the issue.

1- Find a suitable exchange format and protocol

Here you need to decide what is the most important thing on the communication. Is it speed? Is it error detection? Is it memory footprint? For my project, for instance, I decided that I need my communication to be as error free as possible, with minimal memory footprint (up to 64 bytes) and I don't really care about speed, so I gone for a JSON messaging protocol where the desktop application send a short (up to 64 characters) JSON message and receives a short answer. This solved MY problem, your requirements might be different. If you need speed and don't care for memory, for instance, you can use a binary protocol with a header specifing size, the message and a CRC footer to check vailidity. Or you can use BSON and take this library to avoid the hassle.

Serial Interface Definition

2- Define the Serial Polling CycleHow will the arduino firmware knows it is time to send or receive messages? It is always talking? Always ready to receive? It looks at the serial port buffer once each few microsseconds to know if there is an incomming message? How that is handled by your device? If you just need to output data without bothering whether there is someone listening or not, like an GPS device, just throw a Serial.print now and then, but if you need to wait for data, you will have to compartimentalize the process inside an FSM or using some kind of scheduler. If you are not using a scheduler, I recommend this one.

3- Define the Communication CycleHere you will take the data from serial port and storing it on a buffer for later usage.The trick here is1- Check the serial FIFO for incomming data. Serial.available() does it already.2- If there is incomming data, copy the data to next available space in the buffer.3- Check if there is more incomming data after a few millisseconds.4- If there is no incomming data, mark the buffer as ready to use, and parse it.

The following code is unscheduled for simplicity,and I recommend you to replace the sleep() calls to proper scheduling least you want the arduino go unresponsive. It is also waiting text data, so you will need to make changes if you are waiting binary data.

Luiz MenezesLuiz Menezes

SPI is a synchronized interface, it has master and slave. Either you need to switch between slave and master, or you need to provide a way to let Arduino start 'reading' from the other end, since the one who initiates the communication in SPI or I2C is a master, in your case, Arduino, I suppose. The simplest way to do this is to provide another line via gpio. As for generic question, to do two-way communication properly, you probably want to choose asynchronous protocol like UART.

meriororen

I had a similar requirement and came up with Wirekite. It is a complete solution based on a Teensy board, some code for it plus libraries for Mac or PC.

With Wirekite, you can hook up digital and analog inputs and outputs, I2C devices and SPI devices (very soon) to the Teensy board and connect the Teensy board via USB to your Mac or PC. You can then control the I/Os, I2C and SPI buses from you Mac or PC. You don't need to adapt the code on the Teensy.

Usb Interface

Wirekite uses a custom protocol for the communication. But you don't need to care about that because you can simply use the far more convenient API provided by the Wirekite libraries (.NET for Windows, Objective-C/Swift for MacOS).

Interface
Codo

If you want to communicate from the computer to the arduino, use USART. Arduino already has this pre-programmed, as well it's own GUI.

Arduino Serial Interface Guitar

JoeyJoey

Arduino Serial Interface

Not the answer you're looking for? Browse other questions tagged matlab or ask your own question.

Gui For Arduino

Next in Idle create a new window and create the below program.
from time import sleep
import serial
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600) # Establish the connection on a specific port
counter = 32 # Below 32 everything in ASCII is gibberish
while True:
counter +=1
ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino
print ser.readline() # Read the newest output from the Arduino
sleep(.1) # Delay for one tenth of a second
if counter 255:
counter = 32

Two things to keep in mind. To determine what serial port your Arduino is connected to look at the bottom right corner of your Arduino sketch. Whatever that is should be what is in quotes in line 3 of the Python program.
You can also change the baud rate in line 3 of the Python program and line 2 of the Arduino program as long as they stay the same.
Once you run the program it will print out the majority of ASCII characters. By first sending them to the Arduino, which will in turn send it back to the computer that Python then prints out.