KalbeAbbas
Published © MIT

Make Your Remote Control with XinaBox, Zerynth and Ubidots

Learn how to use XinaBox xChip SH01 – capacitive touch sensor – with Ubidots to control devices remotely from anywhere.

BeginnerFull instructions provided15 minutes623
Make Your Remote Control with XinaBox, Zerynth and Ubidots

Things used in this project

Hardware components

CW02
XinaBox CW02
×1
IP01
XinaBox IP01
×1
SH01
XinaBox SH01
×1
XC10
XinaBox XC10
×1
(Optional) USB extenion cable
×1

Software apps and online services

Ubidots
Ubidots
Zerynth Studio
Zerynth Studio

Story

Read more

Code

main.py

Python
Create new Zerynth project and add two files: main.py and helpers.py
Enter your Wi-Fi credentials and Ubidots TOKEN where indicated:
import streams
from wireless import wifi
from xinabox.sh01 import sh01

streams.serial()

# SH01 instance
SH01 = sh01.SH01(I2C0)

from espressif.esp32net import esp32wifi as wifi_driver
wifi_driver.auto_init()

from ubidots.iot import iot

# configure SH01
SH01.init()

print('connecting to wifi...')
 
#Connect to the specified Wi-Fi device
while not wifi.is_linked():
    try:
    # FOR THIS EXAMPLE TO WORK, "Network-Name" AND "Wifi-Password" MUST BE SET
    # TO MATCH YOUR ACTUAL NETWORK CONFIGURATION
      wifi.link("SSID",wifi.WIFI_WPA2,"PASSWORD")
      print("Link Established")
    except Exception as e:
      print("ooops, something wrong while linking :(", e)
      print(".")
    sleep(1000)
 
print('connecting to mqtt broker...')
try:
    #Enter your DEVICE-NAME and Unique Ubidots TOKEN
    device = iot.Device('DEVICE-NAME','business','TOKEN')
    device.mqtt.connect()
    print("Connected to mqtt broker")
except Exception as e:
    print("ooops, something went wrong :(", e)
    while True:
       sleep(1000)
 
device.mqtt.loop()
btn=0
btnPrev=0
while True:
    button = SH01.touched()         # return which button is pressed
    if button  == 'square':         # square touched
        btn=-1
        print('SQUARE TOUCHED')
    elif button == 'triangle':      # triangle touched
        btn=2
        print('TRIANGLE TOUCHED')
    elif button == 'circle':        # circle touched
        btn=1
        print('CIRCLE TOUCHED')
    elif button == 'cross':         # cross touched
        btn=-2
        print('CROSS TOUCHED')
      
    #Publish only if different button is touched  
    if((button) and (btn!=btnPrev)):   
        device.publish({"value":btn},variable="buttonPressed")
        btnPrev=btn
    sleep(100)

helpers.py

Python
Auxiliary code for Ubidots Library
import json

def load_device_conf():
    confstream = open('resource://device.conf.json')
    conf = ''
    while True:
        line = confstream.readline()
        if not line:
            break
        conf += line
    return json.loads(conf)

Credits

KalbeAbbas

KalbeAbbas

25 projects • 20 followers
An enthusiastic and dedicated Electronic engineer graduated from SSUET Karachi, Pakistan. Loves to discover Embedded electronics projects.
Thanks to XinaBox.

Comments