vendredi 16 décembre 2011

apache -> android -> serial -> arduino

La c'est un peu compliqué

1 etape : accès root à Android.

Pour moi c'est un htc et en fouillant un peu j'ai trouvé un site pour débloquer l'accès root.


2 etape : root sur android a quoi ca sert?

J'ai encore bien tout saisi tout ce que l'on pouvait faire, mais il faut trouver comment faire un serveur apache/

plusieurs pistes
http://code.google.com/p/i-jetty/
les paquetages org.apache.http dans le sdk de android. Déjà plus costaud
en java http://tjws.sourceforge.net/index.html

maintenant la problématique est plus java -> serial android
des pistes également
ici

http://v-lad.org/projects/gnu.io.android/

http://code.google.com/p/android-serialport-api/source/browse/trunk/project/src/android/serialport/?r=8

3 etape Le serial

Pour ca plusieurs truc. Apparement un cable Nokia DCU-5 coupé peut faire l'affaire

couplé à un max 3232 si on doit repartir sur du 5V ce qui est notre cas avec l'arduino.

mardi 13 décembre 2011

processing -> arduino -> servo

But contrôler un servomoteur.

Code processing

import controlP5.*;

import processing.serial.*;
Serial myPort; // The serial port


ControlP5 controlP5;

public int myColorRect = 200;

public int myColorBackground = 100;

//variable global
int slide1;

void setup() {
size(400,400);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("sliderA",63,118,100,100,260,100,14).setId(4);
controlP5.addTextfield("textA",100,290,100,20).setId(5);
println(Serial.list());

String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}

void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0,0,width,100);
myPort.write(slide1);
}


// a slider event will change the value of textfield textA
public void sliderA(int theValue) {
((Textfield)controlP5.controller("textA")).setValue(""+theValue);
}

// for every change in textfield textA, this function will be called
public void textA(String theValue) {

println("### got an event from textA : "+theValue);
slide1=int(theValue);
println("slide 1 : "+slide1);

}

public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id());
}


Code arduino

#include

Servo myservo;

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
int pos;

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println((int)incomingByte, DEC);
pos=int(incomingByte);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);

}
}

Et voila ca marche

Il a juste fallut régler la plage de valeur du servo pour ne pas le mettre en buté. La consomation du servo est également à surveiller. Parfois il demande pas mal mais c'est surtout quand il arrive en butée. Généralement et en fonctionnement normal c'est de l'ordre de 0,10 à 0,30A max

processing -> arduino

Enfin la communication série fonctionne

Code arduino

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println((int)incomingByte, DEC);
}
}

Code processing

import controlP5.*;

import processing.serial.*;
Serial myPort; // The serial port


ControlP5 controlP5;

public int myColorRect = 200;

public int myColorBackground = 100;

//variable global
int slide1;

void setup() {
size(400,400);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("sliderA",0,200,100,100,260,100,14).setId(4);
controlP5.addTextfield("textA",100,290,100,20).setId(5);
println(Serial.list());

String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}

void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0,0,width,100);
myPort.write(slide1);
}


// a slider event will change the value of textfield textA
public void sliderA(int theValue) {
((Textfield)controlP5.controller("textA")).setValue(""+theValue);
}

// for every change in textfield textA, this function will be called
public void textA(String theValue) {

println("### got an event from textA : "+theValue);
slide1=int(theValue);
println("slide 1 : "+slide1);

}

public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id());
}

controlP5 slider

Code processing


import controlP5.*;

ControlP5 controlP5;

public int myColorRect = 200;

public int myColorBackground = 100;


void setup() {
size(400,400);
frameRate(25);
controlP5 = new ControlP5(this);
controlP5.addSlider("sliderA",100,200,100,100,260,100,14).setId(4);
controlP5.addTextfield("textA",100,290,100,20).setId(5);

}

void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0,0,width,100);
}


// a slider event will change the value of textfield textA
public void sliderA(int theValue) {
((Textfield)controlP5.controller("textA")).setValue(""+theValue);
}

// for every change in textfield textA, this function will be called
public void textA(String theValue) {
println("### got an event from textA : "+theValue);
}

public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.controller().id());
}

lundi 12 décembre 2011

Control P5

Comment contrôler de manière graphique des données numérique.

Beaucoup de choix sous processing.
ControlP5
proControl

Et bien plus encore

ControlP5 et proControl ont l'air assez similaire.

Je vais tenter controlP5.
1-/ L'installation.

Après avoir télécharger la librairie il faut l'installer. Il faut respecter la procédure. Sur un mac creer un repertoire libraries sous le repertoire Documents/Processing. Et copier la bibliothèque ici le répertoire controlP5 dans le répertoire librairies.



2-/ Programme de test.
la biliothèque à l'air assez étendue.




Le but est de créer une valeur numérique avec un slider
Code processing

import controlP5.*;
ControlP5 controlP5;
int Int; // Need here in this case.
void setup() {
controlP5 = new ControlP5(this);
controlP5.addSlider("Int",0,180,3,10,height/2,60,20);
}

void draw(){}

void controlEvent(ControlEvent theEvent) {
if(theEvent.controller().name()=="Int")
{
println((int)theEvent.controller().value());
}
}


et ca marche.



Pour aller plus loi sur controlP5
http://www.mon-club-elec.fr/pmwiki_reference_processing/pmwiki.php?n=Main.LibrairieGUIcontrolP5

La liste des commandes et leurs syntaxes

communication monde reel -> arduino

Le programme sur l'arduino est le suivant.

CODE
int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println((int)incomingByte, DEC);
}
}


L'un des problèmes majeur est que via le terminal nous envoyons des caractères ASCII et non pas des valeurs

If input a 1 in it should show 1 right?

Well it instead it says:

I received: 49

For the letter A it says:

I received: 69


OUPS

L'une des idées est d'envoyer des valuers entières via processing sur le port série et de lire les réponses donnée par l'arduino

CODE sous processing
// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;

// List all the available serial ports:
println(Serial.list());

/* I know that the first port in the serial list on my mac
is always my Keyspan adaptor, so I open Serial.list()[0].
Open whatever port is the one you're using.
*/
myPort = new Serial(this, Serial.list()[0], 9600);

// Send a capital A out the serial port:
while(keyPressed != true)
{
myPort.write(65);
}




L'une des difficultés est maintenant de faire lire à processing des données rentrées au clavier dans le même programme.


Attention pour rentrer les valeurs il faut selectionner la fenêtre de dessin




Code processing pour rentrer des valeurs
void draw() {
println(key);
}

Autre truc: il faut a chaque fois fermer le terminal avant de lancer une nouvelle utilisation du port série.

code processing

import processing.serial.*;

Serial myPort; // The serial port
int whichKey = -1; // Variable to hold keystoke values
int inByte = -1; // Incoming serial data

void setup() {
size(400, 300);
// create a font with the third font available to the system:


// List all the available serial ports:
println(Serial.list());

// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// In Windows, this usually opens COM1.
// Open whatever port is the one you're using.



String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}

void draw() {

}


void keyPressed() {
// Send the keystroke out:
myPort.write((int)key);
whichKey = key;
}

meme probleme les caractéres arrivent en ascii


code
import processing.serial.*;

Serial myPort; // The serial port
int whichKey = -1; // Variable to hold keystoke values
int inByte = -1; // Incoming serial data

void setup() {
size(400, 300);
// create a font with the third font available to the system:


// List all the available serial ports:
println(Serial.list());

// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// In Windows, this usually opens COM1.
// Open whatever port is the one you're using.



String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}

void draw() {

}


void keyPressed() {
// Send the keystroke out:
int entier;
//char[] ascii;
//ascii=key;
entier=int(key);
myPort.write(entier);
println(key);

}


liens
http://wiki.processing.org/w/Tom_Igoe_Interview

mercredi 7 décembre 2011

Table CNC

un truc que j'avais et que j'ai envie de faire depuis un moment. Une table fraiseuse 3D CNC enfin je sais pas trop comment ca s'appele.

1er étape rassembler le nécessaire:
http://www.shapeoko.com/downloads

Bien lire le wiki

La suite sera pour bientôt...