Raspberry Pi
Raspberry Pi 3 Jessie – LAMP SERVER
Steps to setup LAMP on Raspberry Pi3 Jessie
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo service apache2 restart
or
sudo /etc/init.d/apache2 restart
test by entering the IP address in a browser
sudo apt-get install mysql-server php5-mysql
When installing MySQL you will be asked for a root password.
sudo service apache2 restart
sudo apt-get install phpmyadmin
Raspbian Jessie Mosquitto Broker
Install Mosquitto Broker in few steps (Raspbian Jessie)
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
rm mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update
sudo apt-get install mosquitto
Nextion Raspberry Pi UI
A quick project to connect a Nextion HMI to Raspberry Pi and get some text displayed. (Or whatever goes through your mind)
I am using a Chinese version (I am in China!) of 2.8″ 320×240 device.
- The Nextion project
I made a simple screen with 4 text field to receive data form the RPI.
The text field are named: t0, t1, t2, t3.
Here is the project file (download and rename it as rpi_hmi.HMI)
- Connect the Nextion HMI to RPI. (Pinout from http://www.element14.com – Thanks)
Connect + 5 VDC to pin 2
Connect GND to pin 6
Connect Rx to pin 8
Connect Tx to pin 10
- To send data to the screen I am using my favorite application: Node-Red.
From Node-Red it is possible to run commands and send them to the serial port.
Before that we should make sure that the serial port is available.
If RPI 2, read this post.
If RPI 3, read this post.
In PRI 3 , to use ttyAMA0 it is necessary to stop the bluetooth.
To send data to the Nextion, we should format them like:
t0.txt=, 0x22, text to send, 0x22, 0xFF, 0xFF, 0xFF
Here is the Node-Red flow.
[{"id":"244f48cf.81b92","type":"inject","z":"7a00aa0e.a9b7d4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":128.5,"y":136,"wires":[["e0180d8.3c9047"]]},{"id":"e0180d8.3c9047","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n var ascii = s_object.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n var ascii = s_text.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":288.5,"y":135,"wires":[["858c79ee.44437"]]},{"id":"858c79ee.44437","type":"serial out","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":502.5,"y":134,"wires":[]},{"id":"2466d4ba.b7759c","type":"serial-port","z":"7a00aa0e.a9b7d4","serialport":"/dev/ttyAMA0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"100","bin":"bin","out":"time","addchar":false}]
Another flow to display the CPU temperature
[{"id":"244f48cf.81b92","type":"inject","z":"7a00aa0e.a9b7d4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":128.5,"y":136,"wires":[["e0180d8.3c9047","3c8c3ccb.ea114c","ef39e89d.a084d"]]},{"id":"e0180d8.3c9047","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello World\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n var ascii = s_object.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n var ascii = s_text.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":288.5,"y":135,"wires":[["858c79ee.44437"]]},{"id":"858c79ee.44437","type":"serial out","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":636.5,"y":138,"wires":[]},{"id":"8d36ba49.d16358","type":"serial in","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":112.5,"y":414,"wires":[["9057e978.8b3c"]]},{"id":"9057e978.8b3c","type":"debug","z":"7a00aa0e.a9b7d4","name":"","active":true,"console":"false","complete":"false","x":398.5,"y":417,"wires":[]},{"id":"3c8c3ccb.ea114c","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t1.txt=\";\ns_text = \"Line 2\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n var ascii = s_object.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n var ascii = s_text.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":289,"y":199,"wires":[["858c79ee.44437"]]},{"id":"ef39e89d.a084d","type":"exec","z":"7a00aa0e.a9b7d4","command":"vcgencmd measure_temp","addpay":false,"append":"","useSpawn":false,"timer":"","name":"measure temp","x":347,"y":295,"wires":[["b985e249.4f6ff8"],[],[]]},{"id":"b985e249.4f6ff8","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t2.txt=\";\ns_text = msg.payload;\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n var ascii = s_object.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n var ascii = s_text.charCodeAt(i);\n arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":286,"wires":[["858c79ee.44437"]]},{"id":"2466d4ba.b7759c","type":"serial-port","z":"7a00aa0e.a9b7d4","serialport":"/dev/ttyAMA0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"500","bin":"bin","out":"time","addchar":false}]
Enjoy.
Raspbian Jessie – Enable ttyAMA0
I spent a bit of time trying to find out how to enable the gpio port /dev/ttyAMA0.
- In terminal
sudo raspi-config
- Select 9 Advanced Options
- Select A7 Serial
- Select No for: Would you like a login shell to be accessible over serial?
- reboot
- Enable uart in /boot/config.txt
- reboot
- Done
to check tty:
dmesg | grep tty
Use command-line gpio util to check state of all pins
gpio readall