Rucksikaa Raajkumar
Published © MIT

Real-time monitoring system using PSoC 6

Create your own real-time monitoring system using PSoC 6 and Adafruit IO

IntermediateFull instructions provided3 hours228
Real-time monitoring system using PSoC 6

Things used in this project

Hardware components

CY8CPROTO-062-4343W
Infineon CY8CPROTO-062-4343W
×1
S2GO 3D TLE493DW2B6-A0
Infineon S2GO 3D TLE493DW2B6-A0
Magnetic field sensor
×1
S2GO HALL TLE4964-3M
Infineon S2GO HALL TLE4964-3M
Hall effect switch shield
×1
TLE5012B E1000 MS2GO
Infineon TLE5012B E1000 MS2GO
Magnetic angle sensor
×1

Software apps and online services

Arduino Lab for Micropython
Adafruit

Story

Read more

Schematics

Schematic

The PWM pin (9th pin) of hall sensor must be connected to pin 10.0 of the PsoC 6 microcontroller board

Code

Code

MicroPython
Upload this code and if your code has been uploaded successfully, you should be able to see your sensor data being visualized in your feed
from machine import ADC,Pin
from utime import sleep,sleep_ms

import network
import mip

#user configuration details
ssid 	 = '<YOUR SSID>'
key 	 = '<YOUR PASSCODE>'
username = '<YOUR ADAFRUIT USERNAME>'
adafruitIOKey = '<YOUR ADAFRUIT IO KEY>'
pubTopic_thermistor = '<YOUR ADAFRUIT ACCOUNT USERNAME>/feeds/<FEED_NAME>' 
pubTopic_hall = '<YOUR ADAFRUIT ACCOUNT USERNAME>/feeds/<FEED2_NAME>'

def install_deps():
    ''' Helper function to install all required modules '''
    mip.install("umqtt.simple")

def network_connect() :
    ''' Helper function to connect to network '''
    wlan = network.WLAN(network.STA_IF)
    if wlan.isconnected():
        print('[network-module] : Already connected')
        return
    # enable and connect wlan
    wlan.connect(ssid,key)
    # wait for connection to establish
    sleep(5)
    if not wlan.active():
        print("[network-module] : Connection failed.Try again!")
        return

def database_connect() :
    ''' Helper function to connect to IoT Cloud platform'''
    from umqtt.simple import MQTTClient
    
    client = MQTTClient(client_id=b"Psoc6",
                    server=b"io.adafruit.com",
                    port=0,
                    user=username,
                    password=adafruitIOKey,
                    keepalive=7200,
                    ssl=True,
                    ssl_params={'server_hostname':'io.adafruit.com'}
                    )
    status = client.connect()
    if not status:
        print("[db-module] : Connection to adafruit.io successful!")
    return client

def thermistor_init():
    
    thermistor = ADC(Pin("P10_1"))
    
    return thermistor
    
def hall_init():
    hall = ADC(Pin("10_0"))
    return hall
        
def read_sensor_data_and_stream_to_cloud(thermistor2Obj, hall2Obj, dbObj):
    ''' Helper function to read sensor data and stream to cloud DB
        Args :   thermistor2Obj - Sensor Object (Thermistor)
                 hall2Obj - Sensor Object (Hall sensor)
                 dbObj  - Database Object
        Returns: None
    '''
    # wait for the value to be ready
    sleep(10)
    #get temperature values
    thermistor_val = thermistor2Obj.read_u16()/65535
    thermistor_volt = 3.3*thermistor_val
    print("[thermistor] : value: ", thermistor_volt)
    #get hall sensor values
    hall_val = hall2Obj.read_u16()/65535
    print("[hall] : value: ",hall_val)
    # Stream data to IoT cloud
    dbObj.publish(pubTopic_thermistor,b'{"value":' + str(thermistor_volt) + '}')
    dbObj.publish(pubTopic_hall,b'{"value":' + str(hall_val) + '}')
    
def main():
    ''' Application Main '''
    print('*** PoC demo for micropython enablement for PSoC6 ***\n')
    # Connect to network
    network_connect()
    # Install dependencies
    install_deps()
    # Connect to cloud platform
    dbObj = database_connect()
    # Initialize sensor
    thermistor2Obj = thermistor_init()
    hall2Obj = hall_init()
    
    sleep(1)
    
    while True:
            #Read sensor value and stream to IoT cloud
            read_sensor_data_and_stream_to_cloud(thermistor2Obj, hall2Obj, dbObj)
        
                
if __name__ == "__main__":
    main()

Credits

Rucksikaa Raajkumar

Rucksikaa Raajkumar

43 projects • 93 followers
Amateur Arduino Developer. Undergraduate. YouTuber (https://www.youtube.com/c/RucksikaaRaajkumar/videos) and Blogger (Arduino Projects by R)

Comments