Project – adding an LCD and button to see and send MQTT events
We can use the AdafruitIO dashboard to post messages to our MQTT feed, and so we'll use an LCD to show what we've sent. We'll also wire up a button that will send an MQTT message when pushed.
Wiring it all up
First, we'll wire our LCD to the I2C pins, and our button to GPIO #5, also known as P1-29:
Â

Coding it all together
In a file in the same folder, create mqtt-button-lcd.js
. Put in the usual Johnny-Five and Raspi-IO constructors, and in the board-ready handler:
Then, add the client constructor for AdafruitIO's MQTT connection from mqtt-test.js
. We'll also set up our LCD and button objects here:
letLCD=newfive.LCD({ controller:"PCF8574", rows:2, cols:16 }) letbutton=newfive.Button('P1-29')
After that, we're ready to code the sending of messages on the press of the button, and the printing of messages received on the LCD:
client.on('connect', () => { console.log('Connected to AdafruitIO') client.subscribe(process.env.ADAFRUIT_IO_FEED...