mardi 13 décembre 2011

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...

I2c et arduino

Lancement du projet utiliser le protocole i2c. 1er etape on va essayer avec 2 arduino

site;
http://wiki.t-o-f.info/index.php?n=Arduino.I2C
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235582397
http://arduino.cc/en/Tutorial/MasterWriter
http://www.gammon.com.au/forum/?id=10896


Les questions:
1-/Comment brancher les 2 aduinos en i2c?
2-/Comment transformer un des arduinos en maitre et esclave?
Comment lire les données sur l'un des arduino et vérifier qu'il récupère bien les bonnes données?


Réponses:
1-/Sur la plupart des cartes Arduino:
SDA : broche analogique 4
SCL : broche analogique 5

Un bus I2C (pour Inter Integrated Circuit) est un bus série et synchrone composé de trois fils :
un signal de donnée (SDA) ;
un signal d'horloge (SCL) ;
un signal de référence (masse).

Le périphérique qui gère la communication est le maître, c'est lui qui génère l'horloge (SCL) et qui envoie les données (SDA) mis à part l'acknowledge (acquittement en français).
source : http://fr.wikipedia.org/wiki/I2C

2-/Le brochage est toujours le même pour l'esclave et le maitre. Pas encore bien compris pourquoi.


Exemple maitre/esclave
Code:
#include

void setup()
{
// initialise la liaison I2C en tant que maitre (pas de paramètre à begin)
Wire.begin();
}

void loop()
{
// commence à parler à la carte slave qui a déclaré l'adresse 0x01
Wire.beginTransmission(0x01);
Wire.send("Salut"); // envoie une chaine de caractères (pourrait être un tableau de byte ou...)
Wire.endTransmission(); // arrête
delay(500);
}




Sur l'esclave :

Code:
#include

void setup()
{
// initialise l'I2C en tant que slave (puisque il précise l'adresse 0x01
Wire.begin(0x01);
// déclare une fonction (ci-dessous) pour recevoir ce que le maitre envoit
Wire.onReceive(recevoir);
// pour pouvoir dire ce qui se passe
Serial.begin(9600);
}

void loop()
{
// rien de particulier, le code normal de la carte
delay(100);
}

// déclenché par un envoi du maitre
void recevoir(int qty)
{
Serial.print("> J'ai reçu ");
Serial.print(qty);
Serial.println(" octets.");
// on lit octet par octet
Serial.print("Le maitre dit : ");
while(Wire.available() > 0)
{
char c = Wire.receive();
Serial.print(c);
}
// dernier retour à la ligne
Serial.println();
}





Exemple de transmssion pour un capteur an i2C. Ca peut toujours servir
/*

SRF02 sensor reader

language: Wiring/Arduino Reads data from a Devantech SRF02 ultrasonic sensor.

Should also work for the SRF08 and SRF10 sensors as well.

Sensor connections:

SDA - Analog pin 4

SCL - Analog pin 5

created 5 Mar. 2007

by Tom Igoe

*/

// include Wire library to read and write I2C commands:

#include

// the commands needed for the SRF sensors:

#define sensorAddress 0x70

#define readInches 0x50

// use these as alternatives if you want centimeters or microseconds:

#define readCentimeters 0x51

#define readMicroseconds 0x52

// this is the memory register in the sensor that contains the result:

#define resultRegister 0x02

void setup()

{

// start the I2C bus

Wire.begin();

// open the serial port:

Serial.begin(9600);

}

void loop()

{

// send the command to read the result in inches:

sendCommand(sensorAddress, readInches);

// wait at least 70 milliseconds for a result:

delay(70);

// set the register that you want to reas the result from:

setRegister(sensorAddress, resultRegister);

// read the result:

int sensorReading = readData(sensorAddress, 2);

// print it:

Serial.print("distance: ");

Serial.print(sensorReading);

Serial.println(" inches");

// wait before next reading:

delay(70);

}

/*

SendCommand() sends commands in the format that the SRF sensors expect

*/

void sendCommand (int address, int command) {

// start I2C transmission:

Wire.beginTransmission(address);

// send command:

Wire.send(0x00);

Wire.send(command);

// end I2C transmission:

Wire.endTransmission();

}

/*

setRegister() tells the SRF sensor to change the address pointer position

*/

void setRegister(int address, int thisRegister) {

// start I2C transmission:

Wire.beginTransmission(address);

// send address to read from:

Wire.send(thisRegister);

// end I2C transmission:

Wire.endTransmission();

}

/*

readData() returns a result from the SRF sensor

*/

int readData(int address, int numBytes) {

int result = 0; // the result is two bytes long

// send I2C request for data:

Wire.requestFrom(address, numBytes);

// wait for two bytes to return:

while (Wire.available() < 2 ) {

// wait for result

}

// read the two bytes, and combine them into one int:

result = Wire.receive() * 256;

result = result + Wire.receive();

// return the result:

return result;

}

resultat

prototyper un site web

Il existe plusieurs logiciels permettant de prototyper un site web.
Les gratuits :
pencil project http://pencil.evolus.vn/en-US/Home.aspx
mockflow http://mockflow.com/desktop/
gotrigg gotiggr.com/

Les payants
balsamiq http://balsamiq.com/

Validation

prototyper un site web

Il existe plusieurs logiciels permettant de prototyper un site web.
Les gratuits :
pencil project http://pencil.evolus.vn/en-US/Home.aspx
mockflow http://mockflow.com/desktop/
gotrigg gotiggr.com/

Les payants
balsamiq http://balsamiq.com/

Validation