Aquí se pretende mostrar distintos métodos de realizar un control automático de los procesos industriales.
sábado, 17 de octubre de 2015
martes, 9 de junio de 2015
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
byte gateway[]= {192,168,1,1};
byte subnet[]= {255,255,255,0};
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
float a;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Nuevo cliente");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// Aquí empieza la página
//client.println("<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_djoUUyFaxjIUPt12eqN6dUUWOXgnOfeJV8hFrCMMaM0n3IAKuJkIMTvqnOHm65m-9h_yRJzuPkkB1ZjCGMDOGYZFMUgYqPLKudZU_30M_kgVLPkKMp4xcufIZ3l3ltP75PdI8CdpeUo/s1600/ArduinoUno_R3_thumb.jpg' width='100px' height='100px'></a>"); //Muestra la imagen con la url de la imagen
client.print("<h2>");
client.print("Arduino con Ethernet Shield");
client.print("</h2>");
client.println("<img src='http://www.ntpro.nl/blog/uploads/Arduino.png' width='400px' height='400px'></a>"); //Muestra la imagen con la url de la imagen
client.println("<br />"); // salta de línea
// Devuelve el valor de cada pin de entrada analógica
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
double sensorReading = analogRead(analogChannel); // uso double para poder tener los decimales
client.print("<HEAD><TITLE>Prueba Webserver lectura entradas analogicas</TITLE></HEAD>");
client.print("<body bgcolor='#FFFFFF'>"); //pongo el color del fondo
client.print("<i>");
client.print("Entrada analogica ");
client.print("</i>");
client.print("<b>"); //inicio negrita
client.print(analogChannel);
client.print("</b>"); //fin negrita
client.print(" = ");
client.print(sensorReading);
client.print(" son ");
double b=sensorReading*5/1023;
client.print("<b>"); //inicio negrita
client.print(b);
client.print("Voltios ");
client.print("</b>"); //fin negrita
client.println("<br />");
client.print("<b>--------------------------------------------------------------</b>");
client.println("<br />");
client.print("</body>");
}
client.println("<br />");
client.println("<br />");
client.print("<h2>");
client.print("Llamada a Blog desde Arduino Ethernet Shield");
client.print("</h2>");
client.println("<iframe src='http://www.rjuarez7.blogspot.com.es/' frameborder='5' scrolling='yes' width='350px' height='350px'></iframe>"); // Hago un link a mi blogspot debajo de los valores de las entradas
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(2);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
byte gateway[]= {192,168,1,1};
byte subnet[]= {255,255,255,0};
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
float a;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Nuevo cliente");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// Aquí empieza la página
//client.println("<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_djoUUyFaxjIUPt12eqN6dUUWOXgnOfeJV8hFrCMMaM0n3IAKuJkIMTvqnOHm65m-9h_yRJzuPkkB1ZjCGMDOGYZFMUgYqPLKudZU_30M_kgVLPkKMp4xcufIZ3l3ltP75PdI8CdpeUo/s1600/ArduinoUno_R3_thumb.jpg' width='100px' height='100px'></a>"); //Muestra la imagen con la url de la imagen
client.print("<h2>");
client.print("Arduino con Ethernet Shield");
client.print("</h2>");
client.println("<img src='http://www.ntpro.nl/blog/uploads/Arduino.png' width='400px' height='400px'></a>"); //Muestra la imagen con la url de la imagen
client.println("<br />"); // salta de línea
// Devuelve el valor de cada pin de entrada analógica
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
double sensorReading = analogRead(analogChannel); // uso double para poder tener los decimales
client.print("<HEAD><TITLE>Prueba Webserver lectura entradas analogicas</TITLE></HEAD>");
client.print("<body bgcolor='#FFFFFF'>"); //pongo el color del fondo
client.print("<i>");
client.print("Entrada analogica ");
client.print("</i>");
client.print("<b>"); //inicio negrita
client.print(analogChannel);
client.print("</b>"); //fin negrita
client.print(" = ");
client.print(sensorReading);
client.print(" son ");
double b=sensorReading*5/1023;
client.print("<b>"); //inicio negrita
client.print(b);
client.print("Voltios ");
client.print("</b>"); //fin negrita
client.println("<br />");
client.print("<b>--------------------------------------------------------------</b>");
client.println("<br />");
client.print("</body>");
}
client.println("<br />");
client.println("<br />");
client.print("<h2>");
client.print("Llamada a Blog desde Arduino Ethernet Shield");
client.print("</h2>");
client.println("<iframe src='http://www.rjuarez7.blogspot.com.es/' frameborder='5' scrolling='yes' width='350px' height='350px'></iframe>"); // Hago un link a mi blogspot debajo de los valores de las entradas
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(2);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
domingo, 1 de marzo de 2015
TTL Serial JPEG Camera with Matlab
% This example take a picture using an Arduino hacked to be interfaced as serial conection to the camera
% THIS CODE WORKS PROPERLY NOW.
% Used the LinkSprite JPEG Color Camera TTL Interface from Adafruit.
% rjuarez7@gmail.com 26th of feb 2015
s=serial('com4','baudrate',38400);
set(s,'timeout',10);
%Open serial port
fopen(s);
%Image size. I can select what size I want, in this case I select 640x480
%by puting a '00' at the end of this datagram
tam=hex2dec([ '56' ; '00'; '31'; '05'; '04' ; '00'; '19'; '00']);
fwrite(s,tam,'uint8');
retorno_tam=fread(s,5)
%reset
res=hex2dec([ '56' ; '00'; '26'; '00']);
fwrite(s,res,'uint8');
retorno_res=fread(s,4)
pause(4);
%Take a picture
protocolsign=hex2dec('56');
serialnumber=hex2dec('00');
command=hex2dec('36');
datalength=hex2dec('01');
data=hex2dec('00');
fwrite(s,protocolsign,'uint8');
fwrite(s,serialnumber,'uint8');
fwrite(s,command,'uint8');
fwrite(s,datalength,'uint8');
fwrite(s,data,'uint8');
retorno_getpicture=fread(s,5)
%Stop taking pictures
protocolsign=hex2dec('56');
serialnumber=hex2dec('00');
command=hex2dec('36');
datalength=hex2dec('01');
data=hex2dec('03');
fwrite(s,protocolsign,'uint8');
fwrite(s,serialnumber,'uint8');
fwrite(s,command,'uint8');
fwrite(s,datalength,'uint8');
fwrite(s,data,'uint8');
retorno_stop_picture=fread(s,5)
%Get Fbuffer_Length or read the picture length it is not constant due to
%light....
protocolsign=hex2dec('56');
serialnumber=hex2dec('00');
command=hex2dec('34');
datalength=hex2dec('01');
data=hex2dec('00');
fwrite(s,protocolsign,'uint8');
fwrite(s,serialnumber,'uint8');
fwrite(s,command,'uint8');
fwrite(s,datalength,'uint8');
fwrite(s,data,'uint8');
taille = fread(s,9)%Reads the first 9 bytes
longitud=hex2dec(dec2hex(256*taille(8)+taille(9))) %It Calculates the value in decimal of the picture 256xMSB+LSB
%Close serial port
fclose(s);
%Adjust Input buffer size of the serial object in Matlab to the image number of bytes or length
set(s,'inputbuffersize',longitud);
%Reopen Serial port
fopen(s);
[color=#0000FF]% Thanks to this delay , with the function "pause()", the port in Matlab is open and ready to send the command to the camera to read the image completely in the next lines.[/color]
[b]pause(5); [/b]
[b]%Read picture or Read FBUF[/b]
protocolsign=hex2dec('56');
serialnumber=hex2dec('00');
command=hex2dec('32');
datalength=hex2dec('0c');
dirfinMSB=dec2hex(taille(8));
dirfinLSB=dec2hex(taille(9));
data=hex2dec([ '00' ; '0a'; '00'; '00'; '00'; '00'; '00'; '00'; dirfinMSB; dirfinLSB; 'ff' ;'ff']);
%To send the command to read the image by writing on the serial object s
fwrite(s,protocolsign,'uint8');
fwrite(s,serialnumber,'uint8');
fwrite(s,command,'uint8');
fwrite(s,datalength,'uint8');
fwrite(s,data,'uint8');
B=fread(s,5) %getting response from camera
%pause(2);
if B(4)==0 % If status byte is "0"="success"
'yeah'; %be happy :)
[b]%read the bytes of the image and stores them in the variable buffer_cam
buffer_cam=fread(s,longitud); [/b]
% just for debugging gives the number of bytes in the varible tamano_buffer_cam
tamano_buffer_cam=size(buffer_cam)
end
%Resume FBUFFER
protocolsign=hex2dec('56');
serialnumber=hex2dec('00');
command=hex2dec('36');
datalength=hex2dec('01');
data=hex2dec('02');
fwrite(s,protocolsign,'uint8');
fwrite(s,serialnumber,'uint8');
fwrite(s,command,'uint8');
fwrite(s,datalength,'uint8');
fwrite(s,data,'uint8');
fread(s,5)
fclose(s);
[color=#0000BF]%Creates the jpg file with the next code.
fid = fopen('foto.jpg', 'w');
fwrite(fid, buffer_cam, 'uint8');
fclose(fid);[/color]
Suscribirse a:
Entradas (Atom)