Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
projets:chimeres-orchestra:code-arduino:accueil [2015/05/21 00:09] resonance [Code répéteur autonome (avec piezo) Dublin 06/2012] |
projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:46] (Version actuelle) resonance [Arduino Chimères OSC] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Code Arduino ====== | ====== Code Arduino ====== | ||
+ | A tester ([[http:// | ||
+ | * [[http:// | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | for arduino in / | ||
+ | do | ||
+ | ino upload -m micro -p $arduino | ||
+ | sleep 1 | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Arduino Chimères OSC ===== | ||
+ | * Fichiers : {{: | ||
+ | |||
+ | Réception des données via le protocole OSC. | ||
+ | |||
+ | ++++ chimeres-osc | | ||
+ | <code cpp> | ||
+ | /* | ||
+ | * Chimères Orchestra | ||
+ | * ================= | ||
+ | * Robots drummers in public space by Reson-nance Numérique | ||
+ | | ||
+ | * Website: | ||
+ | * http:// | ||
+ | * | ||
+ | * Setup: | ||
+ | * Ethernet (OSC) > Ethernet Shield > Arduino MEGA > Power Shield MOSFETS > DC Motors | ||
+ | | ||
+ | * Wiring: | ||
+ | * Ethernet Shield | ||
+ | * =============== | ||
+ | * 10 10 (53) | ||
+ | * 11 11 (51) | ||
+ | * 12 12 (50) | ||
+ | * 13 13 (52) | ||
+ | * 5V 5V | ||
+ | * GND GND GND | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | * OSC message: | ||
+ | * /arm Id (int 0-5), PWM (int 0-255), Delay (int 0-100) | ||
+ | | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | |||
+ | // ---- NETWORK ---- // | ||
+ | byte myIp[] = { 192, 168, 0, 105 }; // IP | ||
+ | int serverPort = 9105; // Receive port | ||
+ | byte myMac[] = { 0xED, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address | ||
+ | // 101 UDOO | ||
+ | // 102 { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED } | ||
+ | // 103 { 0xEE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED } | ||
+ | // 104 { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED } | ||
+ | // 105 { 0xED, 0xAD, 0xBE, 0xEF, 0xFE, 0xED } | ||
+ | // 106 { 0xCD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED } | ||
+ | |||
+ | char oscmsg[]="/ | ||
+ | |||
+ | OSCServer server; // to receive messages | ||
+ | |||
+ | // ---- CONFIGURATIONS ---- // | ||
+ | const int PINS[] = {2, | ||
+ | const int TIME_MAX = 120; | ||
+ | const int NB = 6; | ||
+ | const int TEMPO = 10; // sampling tempo | ||
+ | const boolean DEBUG = true; | ||
+ | |||
+ | // ---- MOTORS --------- // | ||
+ | int motor_id, motor_pwm, motor_time; | ||
+ | PwmMotor motors[NB]; | ||
+ | unsigned long current = 0; | ||
+ | |||
+ | // ---- SETUP ----------- // | ||
+ | void setup() { | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | if (DEBUG) Serial.begin(38400); | ||
+ | |||
+ | for (int i=0; i < NB; i++) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // ---- PROGRAM ----------- // | ||
+ | void loop() { | ||
+ | // UPDATE TIME | ||
+ | current = millis(); | ||
+ | |||
+ | if(server.availableCheck()> | ||
+ | // alive | ||
+ | } | ||
+ | |||
+ | // MOTOR OFF | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | if( motors[i].isOn() ) motors[i].off(current); | ||
+ | } | ||
+ | |||
+ | delay(TEMPO); | ||
+ | } | ||
+ | |||
+ | // Get OSC Message | ||
+ | void get_osc(OSCMessage *_mes){ | ||
+ | motor_id=_mes-> | ||
+ | motor_pwm=_mes-> | ||
+ | motor_time=_mes-> | ||
+ | |||
+ | if (DEBUG) { | ||
+ | Serial.print(motor_id); | ||
+ | Serial.print(motor_pwm); | ||
+ | Serial.println(motor_time); | ||
+ | } | ||
+ | | ||
+ | // MOTOR ON | ||
+ | if( motors[motor_id].isOn() == false ) motors[motor_id].on(current, | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | ===== Idem avec capteur de présence (série) ===== | ||
+ | * Fichiers : {{: | ||
+ | |||
+ | |||
+ | ++++ chimeres_capteur | | ||
+ | <code cpp> | ||
+ | // Chimères Orchestra | ||
+ | // Raspberry Pi > Pd > Serial > Arduino MEGA > MOSFETS | ||
+ | // Digital sensor to activate | ||
+ | |||
+ | #include " | ||
+ | |||
+ | // ---- CONFIGURATIONS ---- // | ||
+ | int pins[] = {3, | ||
+ | int time_max = 150; | ||
+ | boolean DEBUG = false; | ||
+ | |||
+ | // ---- VARIABLES --------- // | ||
+ | int id, pwm, time; | ||
+ | const int nb = 6; | ||
+ | PwmMotor motors[nb]; | ||
+ | unsigned long current = 0; | ||
+ | |||
+ | unsigned long button_interval = 50; | ||
+ | unsigned long button_previous = 0; | ||
+ | int button_state = 0; | ||
+ | int button_last_state = 0; | ||
+ | int button_pin = 2; // | ||
+ | |||
+ | |||
+ | // ---- PROGRAM ----------- // | ||
+ | void setup() { | ||
+ | Serial.begin(38400); | ||
+ | for (int i; i < nb; i++) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | current = millis(); | ||
+ | | ||
+ | // Sensor | ||
+ | if(current - button_previous > button_interval) { // sampling | ||
+ | button_previous = current; | ||
+ | button_state = digitalRead(button_pin); | ||
+ | if (button_state != button_last_state) { // if the state has changed | ||
+ | Serial.println(button_state); | ||
+ | } | ||
+ | button_last_state = button_state; | ||
+ | } | ||
+ | |||
+ | // ON | ||
+ | while (Serial.available()) { | ||
+ | id = Serial.parseInt(); | ||
+ | pwm = Serial.parseInt(); | ||
+ | time = Serial.parseInt(); | ||
+ | if (Serial.read() == ' | ||
+ | if( motors[id].isOn() == false ) motors[id].on(current, | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | // OFF | ||
+ | for (int i; i < nb; i++) { | ||
+ | if( motors[i].isOn() ) motors[i].off(current); | ||
+ | } | ||
+ | | ||
+ | delay(5); | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
===== Serial / Arduino / PwmMotor library ===== | ===== Serial / Arduino / PwmMotor library ===== | ||
* Fichiers : {{: | * Fichiers : {{: |