Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


projets:chimeres-orchestra:code-arduino:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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 [2016/11/11 00:07]
resonance [Serial / Arduino / PwmMotor library]
projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:46] (Version actuelle)
resonance [Arduino Chimères OSC]
Ligne 13: Ligne 13:
 </code> </code>
  
 +
 +===== Arduino Chimères OSC =====
 +  * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeresorchestra-arduino-201702.zip|}}
 +
 +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://reso-nance.org/chimeres-orchestra 
 + *
 + * Setup: 
 + * Ethernet (OSC) > Ethernet Shield > Arduino MEGA > Power Shield MOSFETS > DC Motors
 + 
 + * Wiring:
 + * Ethernet Shield  Arduino MEGA  Power Shield
 + * ===============  ============  ============
 + * 10               10 (53)     
 + * 11               11 (51)
 + * 12               12 (50)
 + * 13               13 (52)
 + * 5V               5V
 + * GND              GND           GND
 +                  2             3
 +                  3             5
 +                  5             6
 +                  6             9
 +                  7             10
 +                  8             11
 + 
 + * OSC message: 
 + * /arm Id (int 0-5), PWM (int 0-255), Delay (int 0-100)
 + 
 +*/
 +
 +#include <SPI.h>
 +#include <Ethernet.h>
 +#include <ArdOSC.h>
 +
 +#include "PwmMotor.h"
 +
 +// ---- 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[]="/arm";
 +
 +OSCServer server; // to receive messages
 +
 +// ---- CONFIGURATIONS ---- //
 +const int PINS[] = {2,3,5,6,7,8}; // pins Mosfets Shield (for MEGA because Ethernet Shield use 10,11,12,13 pin and 4th pin for SD Card)
 +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() {
 + Ethernet.begin(myMac,myIp); 
 + server.begin(serverPort);
 + server.addCallback(oscmsg, &get_osc); // callback function (receive)
 +
 + if (DEBUG) Serial.begin(38400);
 +
 + for (int i=0; i < NB; i++) {
 +     motors[i].init(PINS[i], TIME_MAX, DEBUG);
 +  }
 +}
 +
 +// ---- PROGRAM ----------- //
 +void loop() {
 +  // UPDATE TIME
 +  current = millis();
 +
 +  if(server.availableCheck()>0){
 +    // 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->getArgInt32(0);
 +  motor_pwm=_mes->getArgInt32(1);
 +  motor_time=_mes->getArgInt32(2);
 +
 +  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, motor_pwm, motor_time);
 +}
 +</code>
 +++++
 ===== Idem avec capteur de présence (série) ===== ===== Idem avec capteur de présence (série) =====
   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeresorchestra_arduino_sensor_20161104.zip|}}   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeresorchestra_arduino_sensor_20161104.zip|}}
  
 +
 +++++ chimeres_capteur |
 +<code cpp>
 +// Chimères Orchestra
 +// Raspberry Pi > Pd > Serial > Arduino MEGA > MOSFETS
 +// Digital sensor to activate
 +
 +#include "PwmMotor.h"
 +
 +// ---- CONFIGURATIONS ---- //
 +int pins[] = {3,5,6,9,10,11}; // pins Shield Mosfets
 +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; //2,4,7,8,12,13
 +
 +
 +// ---- PROGRAM ----------- //
 +void setup() {
 +  Serial.begin(38400);
 +   for (int i; i < nb; i++) {
 +     motors[i].init(pins[i], time_max, DEBUG);
 +  }
 +}
 +
 +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() == '\n') {
 +       if( motors[id].isOn() == false )  motors[id].on(current, pwm, time);
 +     }
 +   }
 +  
 +  // OFF
 +  for (int i; i < nb; i++) {
 +     if( motors[i].isOn() ) motors[i].off(current);
 +  }
 +  
 +  delay(5);
 +}
 +</code>
 +++++
 ===== Serial / Arduino / PwmMotor library ===== ===== Serial / Arduino / PwmMotor library =====
   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeres_serial_interval_pwm.zip|}}   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeres_serial_interval_pwm.zip|}}
/home/resonancg/www/wiki/data/attic/projets/chimeres-orchestra/code-arduino/accueil.1478819223.txt.gz · Dernière modification: 2016/11/11 00:07 de resonance