Transferring data from Android to Arduino using ADB
in
Android Processing
•
7 months ago
Hello!
I've been working on a project where i want to send a set of variables from an Arduino to an Android device, and have found this code for receiving the data on the Android:
- this.server.addListener(new AbstractServerListener() {
- @Override
- public void onReceive(Client client, byte[] data)
- {
- sensorValueTemp = data[0];
- sensorValueTrykk1 = (data[1]);
- sensorValueTrykk2 = (data[2]);
- sensorValueTrykk3 = (data[3]);
- sensorValueCPS = (data[4]);
- };
- }
And this code for sending the bytes on the Arduino:
- if (millis()-lastTime > 1000)
- {
- byte data[5] = {temperature, trykk1, trykk2, trykk3, CPS};
- connection->write(5,(uint8_t*)&data);
- lastTime = millis();
- }
I'm trying to show the data on the screen of the phone, but nothing shows up, so something is obviously wrong...
- textAlign(CENTER, TOP);
- text(
- "temp: " + (sensorValueTemp) + "\n" +
- "trykk1: " + (sensorValueTrykk1) + "\n" +
- "trykk2: " + (sensorValueTrykk2) + "\n" +
- "trykk3: " + (sensorValueTrykk3) + "\n" +
- "cps: " + (sensorValueCPS), 160, 180);
All of my variables' values should be within the range from 0 to 255, and I've tried to Serial.print them and they show up perfectly there. Have anybody tried something similar before, or see something wrong in the code?
1