Project tutorial
ArduinoLinuxSerial

ArduinoLinuxSerial © LGPL

A simple but robust protocol to send messages (from php, master) and get responses from Arduino via USB. CRC8 and retry in case of error.

  • 703 views
  • 1 comment
  • 1 respect

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Must works whit any Arduino
×1

Apps and online services

Linux PC or TVbox (e,g. MXQ)
To be used as dedicate WEB server
Palapa web server (Android) or LAMP
Ide web
Arduino IDE

About this project

As part of a bigger project, I need a reliable communication between a TVbox (MXQ) and an Arduino board. On the TVbox, used as dedicated Linux PC, will run a web server (Palapa) and a DBMS (mySQL), while the data are collected and commands are processed by an Arduino UNO. This is an alternative to use an Arduino Jùn. The main advantage is the local screen.

So after some googling I build this little project - small, simple and robust:

  • The max length of a master message from php is 60 char (serial Arduino rx buffer limit), the response (from Arduino) as no limits.
  • The LF ('\n', 0x0A) is used internally as delimiter.
  • The protocol uses CRC8 to insure correctness. In case of error the message is resended 3 times before exit in error state.
  • A Bash script (serialArduino.sh) automatically sets the USB serial device on Linux, after every startup or USB re-connection.

Errors

  • ERROR LCRC: bad CRC Linux -> Arduino
  • ERROR ACRC: bad CRC Arduino -> Linux
  • ERROR CODE: sended a command code not implemented in Arduino
  • ERROR SERIAL: USB not plugged, Arduino not running or fail on open the serial device.

A demo allows to control the built-in LED13 by a web page.

See also

Using this ArduinoLinuxSerial the Master is php, and you need the serial driver (it uses devices like /dev/ACMx or /dev/USBx).

Using USBphpTunnel the master is Arduino, and the Android app uses ports like /dev/bus/dev/00X/00Y, so you don't need the serial driver.

Conclusions

Now you can develop MySQL and web-enabled Arduino applications only working on Arduino and PHP. To keep the Arduino Sketch light, you can port all non-realtime logic to PHP side. At the end, your application will work on MXQ+Arduino UNO even 24/7 with only 20 Watt AC power, and can be controlled by smartphone via WiFi.

What more?

Code

All code: bash, php, sketch Arduino
Protocol class (php) ad test example (sketch and php) to control the Arduino from a WEB page, tested on TVbox.

Comments

Similar projects you might like

How to create a website communicating Arduino by using PHP

Project tutorial by Kutluhan Aktar

  • 13,191 views
  • 4 comments
  • 13 respects

Master Slave I2C Connection

by PIYUSH_K_SINGH

  • 3,736 views
  • 0 comments
  • 8 respects

Lcd Display in Real Time.

Project tutorial by Youssef Sabaa

  • 20,146 views
  • 5 comments
  • 44 respects

Simplest Way for Voice Recognition Project Using c#toarduino

Project tutorial by Jalal_Mansoori

  • 8,352 views
  • 28 comments
  • 48 respects

Simple UNO calculator

Project tutorial by Joprp05

  • 6,354 views
  • 0 comments
  • 6 respects

Cable Tester RJ45 (Ethernet)

Project tutorial by Andreaberri

  • 5,708 views
  • 0 comments
  • 8 respects
Add projectSign up / Login