Bluetooth_HC06. Arduino. Dynamic graph. Shift left graph.

4,607 views
Skip to first unread message

Juan Antonio

unread,
Dec 6, 2018, 9:05:19 AM12/6/18
to mitappinv...@googlegroups.com
Hello friends,

this code is based on...


desplazamiento.png

We move a potentiometer and Arduino sends values by Bluetooth.


App Inventor (Android) gets that values and draws a dynamic graph. Shift left graph.

bluetooth_pot2.png

- If you Click PAUSE Button and then START Button, you can look a delay values.

- Change Mac Bluetooth address in code.

// kio4.com

void setup(){
  Serial.begin(9600);
}

void loop (){
    // El terminal central del potenciómetro va a A0 del Arduino
    int i = analogRead(A0);
    i = map(i,0,1024,0,1000);
    Serial.print(i);
    Serial.print("\n"); // Fin de línea. Importante.
    delay(300);    
}
- Regards,
Juan Antonio Villalpando.
scrollingGraph_potenci.aia

Juan Antonio

unread,
Dec 7, 2018, 4:45:15 AM12/7/18
to MIT App Inventor Forum

In this example, Arduino generates a sinusoidal signal and sends the values ​​by Bluetooth.
You can change Resolution, delay, ClockInterval, X scale...and check "Bytes in Buffer"

bluetooth_pot3.png

// Juan Antonio Villalpando

// kio4.com

void setup() 
{ 
Serial.begin(9600);
}


float incremento = 3.14/20; // Resolución
float angulo = 0;
int amplitud = 1000;
int y;

void loop() 
{
y = amplitud * sin(angulo);
angulo = angulo + incremento;
y = map(y,-1000,1000,0,1000);
Serial.print(y);
Serial.print("\n");
delay(400);
}  
scrollingGraph_potenci_simple.aia

Abraham Getzler

unread,
Dec 7, 2018, 10:44:08 AM12/7/18
to MIT App Inventor Forum

Juan Antonio

unread,
Dec 9, 2018, 6:53:05 AM12/9/18
to MIT App Inventor Forum
Thank you Abraham.

This is another version without Clock or delay.

- When Click in Get_Value_Btn, it sends "k" char by Bluetooth.
- In Arduino, if available and read "k" char, then Serial.print(y) by Bluetooth.
- App Inventor value = ReceiveText
- updateGraph.


bluetooth_pot7.png

///////////////////////

void setup() 
{ 
Serial.begin(9600);
}

float incremento = 3.14/20;

float angulo = 0;

int amplitud = 1000;
int y;

char caracter;

void loop() {
 if(Serial.available()) {
   caracter = Serial.read();
   if(caracter == 'k'){ 
   y = amplitud * sin(angulo);

   angulo = angulo + incremento;
   y = map(y,-1000,1000,0,1000);
   Serial.print(y);
   Serial.print("\n");

   caracter = '-';
   }
  }
}

bluetooth_pot5.png

scrollingGraph_potenci_simple_NoClock.aia

Abraham Getzler

unread,
Dec 9, 2018, 12:56:42 PM12/9/18
to MIT App Inventor Forum
This latest version's smooth sine curve could only have
been generated by many button clicks, one per point.

Am I missing something, or are your fingers sore?

ABG

Juan Antonio

unread,
Dec 9, 2018, 3:58:36 PM12/9/18
to mitappinv...@googlegroups.com
My Screen device 5.5 inches

- 41 Click for 1 cycle.

ciclo.png


Reply all
Reply to author
Forward
0 new messages