HeTPro-Tutoriales

Creamos tutoriales de electrónica digital para estudiantes, profesionistasy hoobistas de la electrónica, robótica o mecatronica. Tenemos tutoriales de Arduino, QT-Creator, OpenCV, Electrónica analógica y digital, entre otros temas.

QRE1113 mostrar graficamente los datos

Este tutorial servira para probar el sensor siguielineas con sensores QRE1113. El mismo funciona para cualquier configuracion de sensores QRE1113/QRE1114 o inclusive CNY70 u otros similares que sean analógicos.

En nuestra tienda virtual puedes encontrar varios de esos sensores pero para este tutorial utilizaremos la siguiente tarjeta con sensores qre1113:

https://hetpro-store.com/modulo-sigue-lineas-qre1113/

qre1113
Módulo de sensores QRE1113 de 8 canales.

Puedes descargar el esquematico y boardfile de esta tarjeta en Eagle o PDFs:

https://github.com/HeTpro/SigueLineas-SMSL0208-QRE1113-eagle2

El codigo lo puedes descargar desde github:

https://github.com/HeTpro/SigueLineas-SMSL0208-QRE1113-c/tree/master

O copiar y pegar de final del tutorial.

 

CONEXIONES:

Modulo Sigue-Lineas
Módulo sigue-lineas conectado con Arduino UNO
Siguelineas conexiones
Módulo sigue-lineas conectado con Arduino UNO

Las conecciones entre el sensor y el arduino solo se realizan de la siguiente manera, como se observa mantienen una similitud en nombres, el Vcc va a 5V por que el ADC esta referenciado 5V en el arduino por defecto:

Las conecciones entre la placa de sensores qre1113  y el arduino solo se realizan de la siguiente manera, como se observa mantienen una similitud en nombres, el Vcc va a 5V por que el ADC esta referenciado 5V en el arduino por defecto:

  • Vcc – 5V
  • GND – GND
  • A2 – A0
  • A3 – A1
  • A4 – A2
  • A5 – A3
  • A6 – A4
  • A7 – A5

SETUP PARA CORRER EL EJEMPLO

El codigo tanto de arduino viene comentado, la unica cosa que hay que tomar en cuenta es la siguiente instruccion, cambiar el [1] numero por 0 o 2 si no funciona el codigo.

[code language=»cpp»]
myPort = new Serial(this, Serial.list()[1], 9600);
[/code]

Al abrir el Processing si detecta el arduino se debera de ver la pantalla con las barras como sigue:

Siguelineas en Processing
Sigue-lineas en Processing

El sigue-lineas conectado al arduino video:

CODIGO COMPLETO ARDUINO

[code language=»cpp»]
//HeTPro
//http://www.hetpro.com.mx
//Ejempo para el sensor sigue-lineas.
//qre1113
//Enviar datos de 8 bits por el serial
//Visualizarlos en processing
//Codigo de ejemplo adaptado de:
//http://boolscott.wordpress.com/2010/02/04/arduino-processing-analogue-bar-graph-2/

int Analogue0 = 0;
int Analogue1 = 0;
int Analogue2 = 0;
int Analogue3 = 0;
int Analogue4 = 0;
int Analogue5 = 0;
int inByte = 0;
void setup()
{

Serial.begin(9600);
establishContact();
}
void loop()
{

if (Serial.available() > 0) {

inByte = Serial.read();

Analogue0 = analogRead(0)/4;

delay(10);

Analogue1 = analogRead(1)/4;

delay(10);
Analogue2 = analogRead(2)/4;
delay(10);
Analogue3 = analogRead(3)/4;
delay(10);
Analogue4 = analogRead(4)/4;
delay(10);
Analogue5 = analogRead(5)/4;
delay(10);

Serial.write(Analogue0 );
Serial.write(Analogue1 );
Serial.write(Analogue2 );
Serial.write(Analogue3 );
Serial.write(Analogue4 );
Serial.write(Analogue5 );
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.write(‘A’);
delay(300);
}
}

[/code]

CODIGO COMPLETO PROCESSING

[code language=»cpp»]
//HeTPro
//http://www.hetpro.com.mx
//Ejempo para el sensor sigue-lineas.
//qre1113
//Enviar datos de 8 bits por el serial
//Visualizarlos en processing
//Codigo de ejemplo adaptado de:
//http://boolscott.wordpress.com/2010/02/04/arduino-processing-analogue-bar-graph-2/

// Feel Free to edit these variables ///////////////////////////
String xLabel = «Analogue Inputs»;
String yLabel = «Voltage (V)»;
String Heading = «HETPRO SIGUE LINEAS»;
String URL = «www.hetpro.com.mx»;
float Vcc = 5.0; // the measured voltage of your usb
int NumOfVertDivisions=5; // dark gray
int NumOfVertSubDivisions=10; // light gray
int NumOfBars=6; // you can choose the number of bars, but it can cause issues
// since you should change what the arduino sends
// if these are changed, background image has problems
// a plain background solves the problem
int ScreenWidth = 600, ScreenHeight=400;
/////////////////////////////////////////////////////////
// Serial port stuff ///////////////////////
import processing.serial.*;
Serial myPort;
boolean firstContact = false;
int[] serialInArray = new int[6];
int serialCount = 0;
///////////////////////////////////////////////
int LeftMargin=100;
int RightMArgin=80;
int TextGap=50;
int GraphYposition=80;
float BarPercent = 0.4;
int value;
PFont font;
PImage bg;
int temp;
float yRatio = 0.58;
int BarGap, BarWidth, DivisounsWidth;
int[] bars = new int[NumOfBars];
void setup(){
// bg = loadImage(«BG.jpg»);
/// NB SETTINGS ////////////////////////////////////////////////////////
myPort = new Serial(this, Serial.list()[1], 9600);
////////////////////////////////////////////////////////////////////////
DivisounsWidth = (ScreenWidth-LeftMargin-RightMArgin)/(NumOfBars);
BarWidth = int(BarPercent*float(DivisounsWidth));
BarGap = DivisounsWidth – BarWidth;
size(ScreenWidth,ScreenHeight);
font = createFont(«Arial»,12);
textAlign(CENTER);
textFont(font);
}
void draw(){
// background(bg); // My one used a background image, I’ve
background(250); // commented it out and put a plain colour
// Headings(); // Displays bar width, Bar gap or any variable.
Axis();
Labels();
PrintBars();
}
// Send Recieve data //
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
if (firstContact == false) {
if (inByte == ‘A’) {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you’ve had first contact from the microcontroller
myPort.write(‘A’);// ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 6 bytes:
if (serialCount > 5 ) {
for (int x=0;x<6;x++){
bars[x] = int (yRatio*(ScreenHeight)*(serialInArray[x]/256.0));
}
// Send a capital A to request new sensor readings:
myPort.write(‘A’); // Reset serialCount:
serialCount = 0;
}
}
}
/////// Display any variables for testing here//////////////
void Headings(){
fill(0 );
text(«BarWidth»,50,TextGap );
text(«BarGap»,250,TextGap );
text(«DivisounsWidth»,450,TextGap );
text(BarWidth,100,TextGap );
text(BarGap,300,TextGap );
text(DivisounsWidth,520,TextGap );
}
void PrintBars(){
int c=0;
for (int i=0;i<NumOfBars;i++){
fill((0xe4+c),(255-bars[i]+c),(0x1a+c));
stroke(90);
rect(i*DivisounsWidth+LeftMargin, ScreenHeight-GraphYposition, BarWidth, -bars[i]);
fill(0x2e,0x2a,0x2a);
text(float(bars[i])/(yRatio*(ScreenHeight))*Vcc, i*DivisounsWidth+LeftMargin+BarWidth/2, ScreenHeight-bars[i]-5-GraphYposition );
text(«A», i*DivisounsWidth+LeftMargin+BarWidth/2 -5, ScreenHeight-GraphYposition+20 );
text(i, i*DivisounsWidth+LeftMargin+BarWidth/2 +5, ScreenHeight-GraphYposition+20 );
}
}
void Axis(){
strokeWeight(1);
stroke(220);
for(float x=0;x<=NumOfVertSubDivisions;x++){
int bars=(ScreenHeight-GraphYposition)-int(yRatio*(ScreenHeight)*(x/NumOfVertSubDivisions));
line(LeftMargin-15,bars,ScreenWidth-RightMArgin-DivisounsWidth+50,bars);
}
strokeWeight(1);
stroke(180);
for(float x=0;x<=NumOfVertDivisions;x++){
int bars=(ScreenHeight-GraphYposition)-int(yRatio*(ScreenHeight)*(x/NumOfVertDivisions));
line(LeftMargin-15,bars,ScreenWidth-RightMArgin-DivisounsWidth+50,bars);
}
strokeWeight(2);
stroke(90);
line(LeftMargin-15, ScreenHeight-GraphYposition+2, ScreenWidth-RightMArgin-DivisounsWidth+50, ScreenHeight-GraphYposition+2);
line(LeftMargin-15,ScreenHeight-GraphYposition+2,LeftMargin-15,GraphYposition);
strokeWeight(1);
}
void Labels(){
textFont(font,18);
fill(50);
rotate(radians(-90));
text(yLabel,-ScreenHeight/2,LeftMargin-45);
textFont(font,16);
for(float x=0;x<=NumOfVertDivisions;x++){
int bars=(ScreenHeight-GraphYposition)-int(yRatio*(ScreenHeight)*(x/NumOfVertDivisions));
text(round(x),-bars,LeftMargin-20);
}
textFont(font,18);
rotate(radians(90));
text(xLabel,LeftMargin+(ScreenWidth-LeftMargin-RightMArgin-50)/2,ScreenHeight-GraphYposition+40);
textFont(font,24);
fill(50);
text(Heading,LeftMargin+(ScreenWidth-LeftMargin-RightMArgin-50)/2,70);
textFont(font);
fill(150);
text(URL,ScreenWidth-RightMArgin-40,ScreenHeight-15);
textFont(font);
}

[/code]

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *