Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Aula 💡🕊️
Published © MIT

Hexabitz EXG Biosignal Processing & Visualization in Arduino

Receive muscle signal data from the Hexabitz Single-Lead EXG Monitor using Arduino. Process and visualize data with LED indicators.

IntermediateFull instructions provided3 hours132
Hexabitz EXG Biosignal Processing & Visualization in Arduino

Things used in this project

Story

Read more

Schematics

H2BR0x-Hardware

Code

Arduino Code

Arduino
int incomingByte = 0; // For incoming serial data
char buffer[64] = {0}; // Buffer to store received data
int bufferIndex = 0;   // Index for buffer
const int ledPins[] = {2, 3, 4, 5, 6}; // Pins for LEDs
const int numLEDs = sizeof(ledPins) / sizeof(ledPins[0]); // Number of LEDs

void setup() {
    Serial.begin(921600); // Set baud rate for serial communication
    // Initialize LED pins as OUTPUT
    for (int j = 0; j < numLEDs; j++) {
        pinMode(ledPins[j], OUTPUT);
    }
}

void loop() {
    // Check if data is available on the Serial port
    if (Serial.available() > 0) {
        incomingByte = Serial.read(); // Read incoming byte
        // Add byte to the buffer if it fits, or reset the buffer if it doesn't
        if (bufferIndex < sizeof(buffer) - 1) {
            buffer[bufferIndex++] = (char)incomingByte;
        }

        // If end of message is detected (newline character '\n')
        if (incomingByte == '\n') {
            buffer[bufferIndex] = '\0'; // Null-terminate the string
            bufferIndex = 0; // Reset buffer index for next message

            // Debug: Print the received message
           // Serial.print("Received Message: ");
            //Serial.println(buffer);

            // Extract the last 4 bytes (60 to 63) and convert to numeric value
            if (strlen(buffer) >= 63) { // Ensure the buffer contains at least 63 bytes
                char extractedValue[5] = {0}; // 4 characters + null terminator
                extractedValue[0] = buffer[60];
                extractedValue[1] = buffer[61];
                extractedValue[2] = buffer[62];
                extractedValue[3] = buffer[63];
                extractedValue[4] = '\0'; // Null-terminate the string

                // Convert the extracted ASCII characters to a float
                float sensorValue = atof(extractedValue);

                // Debug: Print the extracted value
                Serial.print("Extracted Sensor Value: ");
                Serial.println(sensorValue);

                // Map the sensor value to the number of LEDs to light up
                int ledIndex = map(sensorValue, 0, 1, 0, numLEDs - 1); // Example range: 0.0 to 1.0
                ledIndex = constrain(ledIndex, 0, numLEDs - 1); // Ensure the index is within range

                // Control the LEDs based on the mapped value
                for (int j = 0; j < numLEDs; j++) {
                    if (j <= ledIndex) {
                        digitalWrite(ledPins[j], HIGH); // Turn on LEDs
                    } else {
                        digitalWrite(ledPins[j], LOW); // Turn off LEDs
                    }
                }
            } else {
                // Debug: Not enough data in the message
                Serial.println("Message too short to process bytes 60 to 63.");
            }
        }
    }
}

H2BR0x-main code

C/C++
/*
 BitzOS (BOS) V0.3.6 - Copyright (C) 2017-2024 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Main function ------------------------------------------------------------*/

int main(void){

	Module_Init();		//Initialize Module &  BitzOS

	//Don't place your code here.
	for(;;){}
}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void *argument){
	EXG_Init(EMG);
	
	// put your code here, to run repeatedly.
	while(1){
		PlotToTerminal(P3);
		HAL_Delay(1000);
	}
}

/*-----------------------------------------------------------*/

H2BR0x-Firmware

Credits

Aula 💡🕊️
58 projects • 224 followers
Electronic Engineering
Contact

Comments

Please log in or sign up to comment.