Skip navigation
Home > All Places > IoT Partner Solutions > Arrow > Blog

Arrow

3 posts

ECG Demo Project

Posted by brev_2458046 Aug 22, 2018

Quicksilver ECG demo

(Project Manager: Bradley Evans; Applications Engineering Interns: Ryan Brooks, Emily Dalton, Fiona Doyle, Gillian Fahey, Amdon Giday, Erik Holmgren, Michael Maxwell, Priscilla Vazquez, and Thomas Wilkinson)

 

The purpose of this project is to demonstrate the capabilities of Cypress’s two featured products, the Quicksilver IoT development board and the PSoC 5LP. This project utilizes the PSoC to simulate the ECG waveforms similar to what an ECG device would output from a patient. We treat the ECG like a black box and simply collect the data streaming from it. The Quicksilver is used for data formatting and wireless communication between the client devices and the access point. This high rate of data flow exemplifies Quicksilver's ability to transmit data reliably. Additionally, we can potentially connect the Quicksilver as a gateway to an analytics application, such as IBM Watson, to detect abnormalities in heart rates. Analytics are the logical next step. All code, 3D models, and guides are attached to this post.

 

What is an ECG?

Electrocardiography (ECG or EKG) is the process of recording the electrical activity of the heart over a period of time using electrodes placed on the skin. These electrodes detect the tiny electrical changes on the skin that arise from the heart muscle's electrophysiologic pattern of depolarizing and repolarizing during each heartbeat. It is very commonly performed to detect any cardiac problems. (Wikipedia)

 

Simulations

The heart rates that we chose to simulate are:

simulations.png

 

Data Flow

 

data blog.png

 

Dashboard

 

dashboard blog.jpg

ECG Dashboard with 6 Quicksilver nodes attached

 

 

How to Set This Up

 

What You'll Need

 

>  2+ Quicksilvers (1 for an access point plus however many clients you want to make)

>  1+ PSoC 5Lp (1 for every device you make)

>  3.7v battery

>  3.7v -> 5v power booster

>  3D printing material

>  Acrylic

>  5 buttons for every device you make

>  Wiring

>  Hinges

>  Super glue

 

 

Electronic Assembly

 

1)  Download all necessary files (I.e. code for Quicksilver access point, client, PSoC code for ECG)

 

2)  Flash Access Point Quicksilver with appropriate software

 

3)  Flash all client Quicksilvers with appropriate software

 

4)  Flash PSoC with ECG simulator files

 

5)  Ensure PSoC is connected to client Quicksilver according to Schematic 1

 

6)  Ensure 5V regulator and battery are connected to Quicksilver according to Schematic 2

 

7)  Connect to the ECG access point (SSID: EKGServer, PASS: ArrowEkg)

 

8)  Navigate to the dashboard at http://192.168.0.1

 

9)  Flip on however many ECG simulators you want to use using the client Quicksilvers and attached PSoCs. (NOTE: ECG simulator will not start until you push a button)

 

 

Hardware Assembly

 

1)  Download all 3D printing files and Laser cutting files

 

2)  Print out all components

 

3)  Cut acrylic to fit lid door

     i)  Laser cutter works best but acrylic can be cut with a dremel

 

4)  Fit acrylic cover into lid, secure with glue along the edges

 

5)  Attach hinges to lid

 

6)  Fit magnets into the slots on the lid edge and the main case and secure

     i)  Make sure the magnets go into BOTH sides in the correct orientation or the lid will not close

 

7)  Fit button bases into the 3D printed shelf, solder the wires appropriately

 

8)  Fit 3D printed buttons on the button bases, secure with glue in the indentation

     i)  Make sure buttons are in the right order, matching the design to the waveform the button will trigger

 

9)  After wiring, slide the PSoC into the runners in the handle of the base, make sure the button shelf remains on top of the upper runners

 

10)  Run power and data wires through the hole between the handle and main chamber of the case

 

11)  With the buttons in place attach the button lid and secure it with glue

 

12)  Attach bottom door over the PSoC and secure with glue

     i)  After programming the PSoC the bottom piece with the USB attachment can be broken off at the perforations to fit in the case

 

13)  Wire Quicksilver to power booster according to the diagram

 

14)  Wire switch to power booster according to the diagram

 

15)  Insert switch into the hold on the right side of the case, power booster should fit into the slot at the top of the case

 

16)  Plug battery into power booster and insert it into the depression in the center of the case

 

17)  Quicksilver will fit into the center chamber above the battery, line up the mounting holes with the screw holes in the case

 

18)  Bring up and attach the wires from the handle according to the wiring diagram

     i)  These wires are from the PSoC that were routed through the hole between the handle and main chamber in step 9

 

19)  Screw the Quicksilver board down into the case

 

20)  Attach the lid by gluing the other side of the hinges to the main case

     i)  Small nails can be used here to help secure the hinges

 

 

 

Wiring

 

ecg1.jpg

Schematic 1: Wiring Schematic for PSoC and Quicksilver Connection

 

 

ecg2.jpg

Schematic 2: Wiring Schematic for Battery, 5V Regulator, and Quicksilver

 

 

 

Analytics

Currently, we're only demonstrating the data stream from an IoT node to webserver; so there are no analytics. In the future, we can connect our data stream to a cloud computing platform for insight about the heart rates. Here we describe how to connect our data stream to Arrow Connect and IBM Cloud.

 

Here's What You'll Need To Do

 

1) Set up an account with Arrow Connect

 

2) Sign up for an IBMid and register with IBM Cloud

 

3) Connect Arrow Connect to the IBM Watson IoT Platform. Detailed instructions on how to do this can be found on the Arrowconnect.io Developer Hub or here.

     i) Create an IoT Watson Platform

     ii) Generate a Watson IoT Application Key & Authentication Token

     iii) Connect Arrow Connect to IBM

 

4) Provision devices in Arrow Connect, and they should populate in IBM automatically. For each device:

     i) Create an Asset Type (the same one will be used by all our Quicksilver devices)

     ii) Create a Gateway (one for each Quicksilver)

     iii) Create a Device (one for each Quicksilver)

     iv) Find HID, API Keys, and Certificates:

          a) HID:

    • Click on the Assets tab, then select Devices.
    • Select the device you have created.
    • Select Developer in the menu on the left.
    • Under the Ingestion tab, find the HID of the Device and copy it.

          b) API Keys:

    • Click on the Access Keys tab next to the Ingestion tab.
    • Click on the the Raw API Key to expand it, and copy it.

          c) Certificates:

    • Click on the button labeled Secure next to the url at the top of the browser.
    • Click on Site Settings at the bottom of the box.
    • Click on the back arrow twice, until you are in the Content Settings.
    • Select Manage Certificates.
    • Select Settings in the drop down box, then scroll down to the bottom of the page and select Advanced.
    • Select the Intermediate Certification Authorities tab.
    • Find and click on DigiCert SHA2 Secu...
    • Click on View.
    • Select the Details tab.
    • Click on copy to File.
    • Click on Next.
    • Select Base-64 encoded X.509 (.CER)
    • Click on Next.
    • Name the file, and save it where you want.

 

5) Download the code (included in a .ZIP file at the bottom) and modify using the HID, API keys, and Certificate.

 

 

 

ECG Software Setup

 

Materials Required:

  • Assembled EKG Nodes (as many as required)
  • Additional QuickSilver or Windows/Linux computer to act as the server
  • WIFI Router optional
  • Computer with WICED Studio and EKGServer WICED code
  • MicroUSB cables

 

Procedure:

  • Configure compile time options for EKGClient code. These include UDP (recommended) or TCP, UDP Multicast (Used if Server IP address will not be known in advance), and Debugging options (DEBUG_PRINT, Packet Return)
  • Compile and flash EKG nodes
  • QuickSilver Server:
  • Configure the EKGServer software to mirror the network settings of the clients.
  • Compile and flash the server firmware.
  • Linux Server:
  • Configure network settings depending on your distribution and the functionality you need.
  • If you intend to use the Linux machine as the hot spot, you will need to configure dnsmasq and hostapd (https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md). Ensure that the created network is NAT type, and that the Linux machine is given the IP address 192.168.0.1
  • If you intend to use an existing network, ensure that UDP_MULTICAST is enabled on the EKGClient firmware, then simply connect the server and clients to this network (EKGClient firmware by default connects to SSID: EKGServer, password: ArrowEkg).
  • The Linux code is written in python3. Install the python3-tornado package (package may be named differently depending on distribution) using either pip3 or your distribution’s package manager.
  • You can configure the python code to start at boot using systemctl (https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6).
  • Windows Server:
  • Install Linux, then follow Linux server steps.

 

Usage:

  • Connect the display device (laptop, maybe a powerful tablet) to the EKGServer network or whichever WIFI network you are using.
  • Navigate to http://191.168.0.1 or the ip address of the server device if you are using UDP_MULTICAST.
  • Power on the nodes with the toggle switch on the side.
  • Nodes may take 10-20 seconds to connect to the router. In theory a status LED on the QuickSilver should turn green once the network connection is made, but this feature still needs a little debugging.
  • As soon as the node is powered on, one of the heartbeat buttons may be pressed. Once the node has finished connecting to the server, the dashboard on the display device will begin to draw the graph of that heartbeat.
  • Impress your customers

Smart Water Dispenser

(Project Manager: Bradley Evans; Applications Engineering Interns: Ryan Brooks, Emily Dalton, Fiona Doyle, Gillian Fahey, Amdon Giday, Erik Holmgren, Michael Maxwell, Priscilla Vazquez, and Thomas Wilkinson)

 

The Water Cooler project began as an innovative idea for exemplifying the abilities of the Cypress and Arrow Quicksilver Board and the Cypress PSoC 5LP. The idea was to build a smart water dispenser that tracks the amount of water remaining in the container , daily water usage, and employee water consumption by day. At fixed time intervals, water level percentages are sent up to the IBM database with associated time stamps so that water levels can be tracked remotely and water refills can be planned accordingly. Additionally, gesture control using CapSense was included for ease of use and controlled water pouring. The goal of this post is to walk through how this demo can be replicated. All code, 3D models, and guides can be found attached to this post.

 

 

Development

 

Water Level Sensor

In designing the water level sensor, the Quicksilver team initially experimented with the CapSense technology and the effects of water and proximity sensing. Our first working model was the water sense strip that could be taped to any bottle and be automatically calibrated. Soon after, we moved to a solution that did not rely on taping a sensor to the bottle, but rather using a spring-loaded hinge to create contact between a solid plate and a fixed water container.

 

Gesture Control

In designing the gesture control, the Quicksilver team tested the effects of proximity on CapSense sensors and developed algorithms for determining motion of close objects based on calibration techniques and calculated spacing between sensors. The first working version was a 4 directional motion pad that could inform the user of the motion of their gesture in real time. For the water cooler, we moved to a 2 directional solution that could be used for easily turning on and off the water supply.

 

Communications

To start the communication between the Quicksilver and IBM IoT Dashboard, we first connected to ArrrowConnect and posted the data to the ArrowConnect Dashboard. Then, we connected IBM through ArrowConnect to post the water level of the water cooler. Once the IBM account information is uploaded and the devices are provisioned in ArrowConnect, they will populate in IBM automatically.

 

 

 

Code

 

Cypress PSoC 5LP

The Cypress PSoC CY8C5888LTI-LP097 was programmed using PSoC creator 4.2. The code controlling the PSoC in the water cooler governs the water level sensor, gesture control, valve control, LED control, and UART transmission. All the code is attached to the post.

The key functions in the PSoC include the following:

 

     >  void wait (uint16 seconds)

          >  Makes user wait for specified time and blinks LED slowly

 

     >  void waitForSwitch ()

          >  Makes user wait until the BLUE button is pressed and blinks LED quickly

 

     >  void readInEEPROMValues (uint16 address)

          >  Reads in the previously recorded water level sensor calibration values after the device is reset or restarted.

 

     >  void writeEEPROMValues (uint16 address)

          >  Writes over the previously recorded water level sensor calibration values so that the device can be unplugged and plugged back in again without losing calibration

 

     >  void adjustValve (uint8 status)

          >  Opens and closes valve

 

     >  void updateCapSensors ()

          >  Updates the perceived value of all water level sensors and gesture sensors

 

     >  void updateWaterFillMonitor ()

          >  Updates the status on the water level

 

     >  void updateGestureControl ()

          >  Updates the status on the gesture sensor

          >  Note: Since this process requires constant re-calibration to work, gesture control is a polling process rather than an interrupt

 

     >  void calibrateWaterFillMonitorEmpty ()

          >  Calibrates values for when water container is empty

 

     >  void calibrateWaterFillMonitorFull ()

          >  Calibrate values for when water container is full

 

     >  void calibrateWaterSensors ()

          >  Initiates process of calibrating the water level

          >  Includes wait times, empty calibration, and full calibration

 

     >  void calibrateGestureControl ()

          >  Calibrates gesture control at startup

 

     >  void recalibrateGestureControl ()

          >  Re-calibrates gesture control whenever perceived gesture values become consistent

 

Cypress Quicksilver

The Cypress Quicksilver was programmed using WICED Studio 6.2. The code controlling the Quicksilver governs the UART communication, Wi-Fi connection, IBM database data transmission. We used existing ArrowConnect libraries from Arrow's Engineering Solution Center to start posting to IBM and ArrowConnect. To fit the water cooler project, we first change the data structure quicksilver_data telemetry_data to only have a unsigned int8 number called waterLevel. Then, we changed the code to accept UART transmissions. In application_start(), we added a UART initialize and a ring buffer initialize for the UART connection from the PSOC. In the arrow_mqtt_send_telemetry_routine() method, we changed the update_sensor_data to update the ring_buffer with the data coming in and storing it into quicksilver_data telemetry_data. To post onto IBM, we added:

json_append_member(_data, TELEMETRY_UART, json_mknumber(data->waterLevel));

to telemetry.c and we added:

#define TELEMETRY_UART              "f|waterLevel"

to config.h.

All this code is included in the post.

 

 

Data Flow

water data.png

 

 

Dashboards

Screenshot (32).png

 

 

 

Assembly

 

Building the Circuit

 

Components

>  Soldering bread board

>  1N1004 Diode

>  1K Ohm Resistor

>  TIP120 Transistor

>  5V Regulator

>  Small Heat Sink (x3)

>  10uF Capacitor (x2)

 

Description

 

schem1.png

 

schem2.png

 

 

Water Level Sensor, Buttons, and Housing

 

Components

>  3D Printed Contoured Face

>  Layered Copper Tape

>  3D Printed Backing

>  3D Printed Button Shelf

>  Red and Blue Buttons

 

Assembly

>  10 Strips of folded copper tape (about 10 folds each) are glued to the surface of the sensor face. Wires are soldered onto the back of each sensor and are soldered the PSoC board according to the Figure. CapSensor 0 is at the bottom of the sensor face and CapSense 9 is at the top of the sensor face.

     >  Note: There is an 11th sensor spot at the base of the face however it is not being used (see unsoldered hold on the left side of the image.)

 

1a.png

 

The Buttons

>  With each of the buttons assembled inside the button shelf, glue the button shelf to the back with the red LED on bottom and blue led on top.

>  Solder connections so that the GND is connected to both buttons, calibrate is connected to the blue button, and Reset is connected to the red button.

>  Once soldering, the face should snap into place in the backing.

1b.png

 

Power Supply

 

Components

>  12V 2A DC Adapter

 

Installation

>  Cut the ends of the wire, strip, and spread apart

>  Use the wire with dashed lines along it as the 12V source and the other as a GND

>  Feed wire though hole in the back of base and secure with tape so that it cannot get pulled back out

 

 

 

Gesture Sensor

 

Components

>  Layered Copper tape

>  Clear Tape

>  White paper

>  Wire

 

Assembly

>  Cut out layered copper tape into 1x4 inch strips. Solder wires onto each strip and tape each strip to the inside of the base using clear tape with white paper in between the copper and the outer part.

>  Each strip should be about 2 inches apart from each other and in the middle of the right side of the container.

>  Note: The white paper makes the copper strips less visible from the outside of the container.

>  Lastly, paint ON/OFF sign on the right side of container so that users know which side to use for controlling the valve

 

 

 

Valve

 

Components

>   2V Solenoid Valve

>  Silicone Sealant

>  Zip ties

>  Valve Lead Connectors

 

Assembly

>  Using the existing rubber tube connecting the faucet head to the base the container, cut out the center portion insert each end into the valve

>  Use silicone sealant to ensure no leakage

>  Connect the rubber ends back to the base and use zip ties to secure the connection

>  Connect the Valve Power and Valve Power to the valve using the valve lead connector. This too will ensure a secure electrical connection

 

 

 

LED and Faucet Head

 

Components

>  3D Printed LED Cap

>  Blue LED

>  White Heat Shrink (x2)

>  Faucet cap

>  Faucet w/ nut

 

Assembly

>  Drill hole directly above faucet

>  Attach faucet with nut

>  Feed white GND wire and another LED wire through hole, solder ends to the blue LED, and apply heat shrinks to cover exposed connections

>  Paint the faucet cap white and screw piece onto top of faucet

>  Mount blue LED inside of white LED cap and glue into top of faucet cap

 

 

 

Mount and Hinge

 

Components

>  3D Printed Mount

>  3D Printed Backing

>  Metal Spring Hinge

>  Super Glue

 

Assembly

>  Drill hole on the top back of the base of the water cooler.

>  Glue base piece onto back and let try

>  Place empty water container in base and align water sensor w/ backing so that the hinge can be glued on properly

>  Glue hinge piece to backing and to base

>  Pull wires through hole in base. Wires to include:

          >  Lower Gesture Sensor

          >  Upper Gesture Sensor

          >  LED wire

          >  Valve Control

          >  5V DC Power

          >  GND

 

 

 

PSoC

 

Assembly

>  Follow Figure to connect:

          >  LED

          >  Valve Control

          >  Upper Gesture Control

          >  Lower Gesture Control

>  Connect white UART wire according to the figure

>  Connect red VDD and black GND wires according to the figure

 

2b.png

 

2.png

 

 

Quicksilver

 

Components

>  3D Printed Quicksilver case

>  Quicksilver board

 

Assembly

>  Glue case to the left side of the base and place Quicksilver inside

>  Connect 5V Power and Ground from base to Quicksilver according to the figure

>  Connect white, red, and black wires from PSoC to Quicksilver according to the figure

 

1.png

 

 

 

Analytics

We can connect our data stream to a cloud computing platform for insight about usage and water levels. Analytics can also aid in planning the best delivery routes, focusing on need based delivery, limiting wasted resources. Here we describe how to connect our data stream to Arrow Connect and IBM Cloud.

 

Here’s What You’ll Need To Do

1) Set up an account with ArrowConnect

 

2) Sign up for an IBMid and register with IBM Cloud

 

3) Connect ArrowConnect to the IBM Watson IoT Platform. Detailed instructions on how to do this can be found on the Arrowconnect.io Developer Hub or here.

     i) Create an IoT Watson Platform

     ii) Generate a Watson IoT Application Key & Authentication Token

     iii) Connect Arrow Connect to IBM

 

4) Provision devices in ArrowConnect, and they should populate in IBM automatically. For each device:

     i) Create an Asset Type (the same one will be used by all our Quicksilver devices)

     ii) Create a Gateway (one for each Quicksilver)

     iii) Create a Device (one for each Quicksilver)

     iv) Find HID, API Keys, and Certificates:

          a) HID:

               >  Click on the Assets tab, then select Devices.

               >  Select the device you have created.

               >  Select Developer in the menu on the left.

               >  Under the Ingestion tab, find the HID of the Device and copy it.

          b) API Keys:

               >  Click on the Access Keys tab next to the Ingestion tab.

               >  Click on the the Raw API Key to expand it, and copy it.

          c) Certificates:

               >  Click on the button labeled Secure next to the url at the top of the browser.

               >  Click on Site Settings at the bottom of the box.

               >  Click on the back arrow twice, until you are in the Content Settings.

               >  Select Manage Certificates.

               >  Select Settings in the drop down box, then scroll down to the bottom of the page and select Advanced.

               >  Select the Intermediate Certification Authorities tab.

               >  Find and click on DigiCert SHA2 Secu...

               >  Click on View.

               >  Select the Details tab.

               >  Click on copy to File.

               >  Click on Next.

               >  Select Base-64 encoded X.509 (.CER)

               >  Click on Next.

               >  Name the file, and save it where you want.

 

5) Download the code and modify using the HID, API keys, and Certificate.

 

 

 

Connecting Quicksilver to IBM IoT Dashboard

1) Copy and paste the Raw API and the Secret API key above into the private.h file below.

     1.png

 

2) Open the terminal for the Quicksilver and set the Baud Rate to 115200.

 

3) Program the Quicksilver with the ArrowConnect.c code.

 

4) The Quicksilver will be broadcasting “Quicksilver Config Access Point” network. Connect to this network in your Wi-Fi settings

 

5) The IP address for the Quicksilver will be posted in the terminal. Copy and paste the IP address into your internet browser.

2.png

 

6) After this, the website below will load, where you can connect to Wi-Fi for the demo. If the Wi-Fi network is not there, refresh the page.

3.png

 

7) After connecting, the terminal will display information about connecting to the network, making a new gateway, and making a new device. This is the gateway and device that will be shown in IBM.

    1. Once connected, the green light on the Quicksilver should be on. If not, the connection is not correct.
    2. The connection is also correct is the data streaming from the PSoc is displaying in the terminal. This should be a number from 0-100.

4.png

 

8) Log into the IBM Cloud Account and click on Internet of Things Platform. Launch the Platform. The page that loads after you launch is a list of devices and gateways. Make note of the gateway that you made with your Quicksilver.

5.png

 

9) Go to the Boards tab (the grid of circles). Click on make a new card. Select the gateway that you created. The event should have a telemetry option and the property should have a f|waterlevel option. If it does not, the connection is not correct or you have the wrong gateway selected. Make the type a number from 0 to 100.

6.png

 

10) After you make a new card, the data displayed should match the data in the terminal streaming every second. This means the connection is correct and you are ready to demo.

7.png

Arrow Connect QS demo Quickstart Guide (see attachments)

Purpose

Demonstrate the capabilities of a Quicksilver Eval Kit by sending sensor data from the Quicksilver Eval Kit to ArrowConnect cloud; contolling RGB LED on your Quicksilver Eval Kit from the ArrowConnect cloud and generating emails based on trigger events sent from your Quicksilver Eval Kit as an IoT device.