week16 complete

parent d97269c7
Pipeline #94041 passed with stage
in 19 seconds
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial myserial(8,7);
Servo myservo;
int led1=5;
int led2=6;
int led3=9;
int valor;
char LED;
int pwm;
void setup() {
Serial.begin(9600);
myserial.begin(9600);// Inicializamos el puerto serie 1
//myservo.attach(6);
pinMode(led1,OUTPUT); //R
pinMode(led2,OUTPUT); //G
pinMode(led3,OUTPUT); //B
pinMode(6,OUTPUT);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
void loop() {
while(myserial.available()>0){
valor=myserial.parseInt();//leemos el primer valor entero y se guarda en la variable
LED=myserial.read();
pwm=map(valor,0,255,255,0);
Serial.println(pwm);
Serial.println(valor);
if(LED=='G')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led2,pwm);//realizamos la escritura analógica
}
if(LED=='B')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led3,pwm);//realizamos la escritura analógica
}
if(LED=='R')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led1,pwm);//realizamos la escritura analógica
}
if(LED=='S')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(6,valor);//realizamos la escritura analógica
}
}
}
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial myserial(8,7);
Servo myservo;
int led1=5;
int led2=6;
int led3=9;
int valor;
char LED;
int pwm;
void setup() {
Serial.begin(9600);
myserial.begin(9600);// Inicializamos el puerto serie 1
myservo.attach(10);
pinMode(led1,OUTPUT); //R
pinMode(led2,OUTPUT); //G
pinMode(led3,OUTPUT); //B
//pinMode(6,OUTPUT);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
void loop() {
while(myserial.available()>0){
valor=myserial.parseInt();//leemos el primer valor entero y se guarda en la variable
LED=myserial.read();
pwm=map(valor,0,255,255,0);
Serial.println(pwm);
Serial.println(valor);
if(LED=='G')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led2,pwm);//realizamos la escritura analógica
}
if(LED=='B')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led3,pwm);//realizamos la escritura analógica
}
if(LED=='R')//Cuando lea el carácter “fin de línea” finaliza el envío
{
analogWrite(led1,pwm);//realizamos la escritura analógica
}
if(LED=='S')//Cuando lea el carácter “fin de línea” finaliza el envío
{
myservo.write(valor);//realizamos la escritura analógica
}
}
}
......@@ -89,17 +89,17 @@
<br><h4>PWM</h4>
The next step I make is the use of PWM using sliders. Each slider must have a minimum value of 0 and a maximum value of 255, as shown in the picture.
<a title="GUI Pwm"><img class="image center" src="images/week16/guipwm.jpg" alt="" /></a>
For this case, a method is created to "set" the data that we will send to Arduino. As the values that we will send will be between 0 and 255, what the software does is send them figure by digit.
If we are going to send for example the 255, Arduino will receive the 2, then the 5 and then the other 5.<br>
What we will do with Arduino will be to receive the hundreds, tens and units. The 2 we multiply it by 100, the 5 by 10 and the last 5 we leave it that way. Then we add them: 200 + 50 + 5 = 255. However, for this to work first you have to send the hundreds, then the tens and finally the units.
If you control a 1, Arduino will multiply it by 100 and then we will not obtain the desired results. What we will do to prevent this from happening is to send "001". So, Arduino will do the following: (0) * 100 + (0) * 10 + 1 = 1.<br>
The same when there are dozens. If we send the 10, we must do it in the following way: «010». Arduino will interpret it in the following way: (0) * 100 + (1) * 10 + (0) * 0 = 10.
For this case, a method is created to "set" the data that we will send to microcontroller. As the values that we will send will be between 0 and 255, what the software does is send them figure by digit.
If we are going to send for example the 255, microcontroller will receive the 2, then the 5 and then the other 5.<br>
What we will do with microcontroller will be to receive the hundreds, tens and units. The 2 we multiply it by 100, the 5 by 10 and the last 5 we leave it that way. Then we add them: 200 + 50 + 5 = 255. However, for this to work first you have to send the hundreds, then the tens and finally the units.
If you control a 1, microcontroller will multiply it by 100 and then we will not obtain the desired results. What we will do to prevent this from happening is to send "001". So, microcontroller will do the following: (0) * 100 + (0) * 10 + 1 = 1.<br>
The same when there are dozens. If we send the 10, we must do it in the following way: «010». microcontroller will interpret it in the following way: (0) * 100 + (1) * 10 + (0) * 0 = 10.
<a title="Set PWM"><img class="image center" src="images/week16/setpwm.jpg" alt="" /></a>
As done with the On and Off button, we will perform the change action according to the position of the slider, as seen in the picture.
<a title="Change Slider"><img class="image center" src="images/week16/changeslider.jpg" alt="" /></a>
The code used by each slider will be the following.
<a title="Slider code"><img class="image center" src="images/week16/slidernetbeans.jpg" alt="" /></a>
What we do is save the reading of the slider in a variable, convert it into a text to be able to write it in a text box and then send that data to the SetData function, after the SetData is sent to the arduino and the color of the box is changed according to the color.<br>
What we do is save the reading of the slider in a variable, convert it into a text to be able to write it in a text box and then send that data to the SetData function, after the SetData is sent to the microcontroller and the color of the box is changed according to the color.<br>
In the arduino ID we load the following code (the code will be found in the downloads section).
<a title="PWM code"><img class="image center" src="images/week16/pwmcode.JPG" alt="" /></a>
Below is a small video of its operation.<br>
......@@ -110,12 +110,38 @@
<br><h2>App Inventor</h2>
<p>
Working
App Inventor is an online software development environment created by Google Labs for the development of applications for the Android operating system.
This environment is quite friendly, and I have experience with the creation of apps, as you can see the projects developed as tests and final applications related to the Arduino.
<a title="App Inventor projects"><img class="image center" src="images/week16/projects.jpg" alt="" /></a>
We will use a list picker for the connection of the Bluetooth and some sliders for the programming of the RGB and the servomotor.
The text parameters are modified to give the desired shape and the maximum and minimum values of the sliders as shown in the picture.
<a title="GUI"><img class="image center" src="images/week16/guiappinventor.jpg" alt="" /></a>
The next step is to configure the connectivity of the bluetooth, for this we select the options before picking and after picking of the list picker.
The before picking must create some elements to the list picker, which will be the addresses and names of the existing bluetooth devices.
In the case of after picking you must select the address of the bluetooth module from the previous list picker.
<a title="Bluetooth connection"><img class="image center" src="images/week16/bluetooth.jpg" alt="" /></a>
To send the data to the microcontroler will be done in text form in which a letter is assigned to define the slider and then its value.
<a title="Red slider"><img class="image center" src="images/week16/redslider.jpg" alt="" /></a>
The blocks for the sliders of the remaining led and the servomotor must be repeated.
<a title="APP Inventor blocks"><img class="image center" src="images/week16/appinventor.jpg" alt="" /></a>
The following code is loaded in our microcontroller.
<a title="Bluetooth code"><img class="image center" src="images/week16/rgbbluetooth.jpg" alt="" /></a>
To install the application, click on build and choose the QR code format. From an Android phone the MIT AI2 Companion application is downloaded and the code is scanned, having the installation of our application.<br>
Once installed, the test of our application is performed, then a demonstration video.
(app video)
</p>
<br><h2>Problems</h2>
<h2>Problems</h2>
<p>
Working
In the netbeans the operation of the PWM did not occur in the expected way, I have reviewed many tutorials and the way of programming is similar to mine, but the videos are at least 2 years ago.
The conclusion I can reach is that the bookstore is new and has that drawback or there is a new way to program.
For this reason, I decided to program with the app inventor.<br>
One problem I found when trying to perform the control with the bluetooth was that the rgb LEDs are in reverse, so I must make a change in the programming, as shown in the picture
<a title="Change pwm"><img class="image center" src="images/week16/changepwm.jpg" alt="" /></a>
The second big problem was with the iteration of the PWM and the servomotor.<br>
<iframe width="560" height="315" src="https://www.youtube.com/embed/7gAxTHI579E" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<br>Independently works very well, but when integrating the servo there are problems. As seen in the week of outputs, the servomotor library can cause interference with other output pins.
</p>
<br><h2>Group</h2>
......@@ -132,6 +158,13 @@
Code with netbeans<br>
<a href="images/week16/ONOFFATMEGA328NETBEANS.ino" download>On Off code.</a><br>
<a href="images/week16/RGBATMEGA328NETBEANSFAIL.ino" download>PWM code.</a><br>
Code with Bluetooth<br>
<a href="images/week16/rgbpwmatmega328.ino" download>PWM code.</a><br>
NetBeans Projects (.zip)<br>
<a href="images/week16/onoff.zip" download>On Off project.</a><br>
<a href="images/week16/rgbLed.zip" download>RGB project.</a><br>
APP Inventor (.apk)<br>
<a href="images/week16/LED_RGB.apk" download>RGB project.</a><br>
</p>
</p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment