How to split data received from Arduino?

I'm trying to work with a CD74HC4067, which is a 16-channel analog multiplexor. I'd like to know how I can split my data so that the values received on my interface are separated according to the channel and voltage I'm using.

So far, my Arduino code looks something like this:

#include <BluetoothSerial.h> // Biblioteca para comunicación Bluetooth Serial

BluetoothSerial SerialBT; // Instancia para la comunicación Bluetooth

int PB[ ] = {32, 33, 25, 26};
float v;

void setup() {
// Inicia los pines como salidas
for (int cont = 0; cont < 4; cont++) {
pinMode(PB[cont], OUTPUT);
}

// Inicia la comunicación Serial y Bluetooth
Serial.begin(115200);
SerialBT.begin("ESP32_Sensor"); // Nombre del dispositivo Bluetooth
Serial.println("ESP32 Bluetooth iniciado...");
}

float medirch(int ch) {
// Configura los pines de acuerdo al canal
digitalWrite(PB[0], (ch & 1) / 1);
digitalWrite(PB[1], (ch & 2) / 2);
digitalWrite(PB[2], (ch & 4) / 4);
digitalWrite(PB[3], (ch & 8) / 8);

// Lee el voltaje desde el pin de entrada analógico
float voltaje = analogRead(36) * 3.3 / 4096.0;
return voltaje;
}

void loop() {
// Lee y envía los valores de los sensores
for (int i = 0; i < 8; i++) {
v = medirch(i);
// Envia los datos por Bluetooth en formato "CH:x=y" (ej. "CH:1=2.52")
String mensaje = "CH:" + String(i) + "=" + String(v);
SerialBT.println(mensaje); // Enviar datos por Bluetooth
Serial.println(mensaje); // También lo manda por el puerto serial (opcional)
}

delay(500); // Retraso entre lecturas (ajustable según lo necesites)
SerialBT.println("==========================="); // Línea separadora para claridad
}

Your sketch looks pretty good, aside from that extra '==================' you send that breaks the pattern of the other messages.

Here's a starter, that you can add labels to, and expand the dictionary of labels with the blue mutator button:


BlueTooth_multichannel_delimiter_sample.aia (3.5 KB)

Also, be aware that the AI2 Charts component can be told about those prefixes (CH:1=, CH:2=,...) to set up ChartData inputs directly from BlueTooth.

1 Like

Here's a sample tailored to your sketch output, with an 8 channel graph based on those prefixes you added.

I don't have your message source, so I can't test it.

I assume the Chart's ChartData Data sources will pick up the incoming data. (I may be wrong, in which case the Clock Timer will have to grab the data and feed it to the ChartData components.)


BlueTooth_multichannel_chart_sample_copy.aia (4.4 KB)

2 Likes

Thanks a lot! Will try to use this.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.