Arduino uno + ethernet shield + iPhone + iOSC(OSC Application)

  • このエントリーをはてなブックマークに追加
    2011/06/11
  • arduino, iPhone

Arduino uno にethernet shieldを乗っけて、iPhoneアプリのiOSCから、OSCのUDPパケットを受信してArduinoに接続された液晶を変更するスケッチ。

液晶接続のポートですが、最初

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

としてたら液晶が表示されなかったので、下のスケッチのようにしたら動くようになりました。接続ポートに注意。また、UDPの受信コードはExamplesのUDPSendReceiveStringを参考にしました。というかそのまんま使いました。

/*
  UDPSendReceive.pde:
 */

#include          // needed for Arduino versions later than 0018
#include 
#include          // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include 

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[]	= { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
byte ip[]	= { 192 , 168 , 1 , 1 } ;  //

unsigned int localPort = 10000;      // local port to listen on

// the next two variables are set when a packet is received
byte remoteIp[4];        // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back
LiquidCrystal lcd(8, 7, 6, 5, 4, 3, 2);

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0, 0);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.available(); // note that this includes the UDP header
  if(packetSize)
  {
    packetSize = packetSize - 8;      // subtract the 8 byte header
    Serial.print("Received packet of size ");
    Serial.println(packetSize);

    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    char* c = packetBuffer;
    if( strcmp(c, "/osc/button1") == 0 ){
      lcd.setCursor(0,0);
      lcd.print("button 1 pushed");
    }
    if ( strcmp(c, "/osc/button2") == 0 ){
      lcd.setCursor(0,0);
      lcd.print("button 2 pushed");
    }
    Udp.sendPacket( ReplyBuffer, remoteIp, remotePort);
  }
  delay(500);
}

“Arduino uno + ethernet shield + iPhone + iOSC(OSC Application)” への4件のコメント

  1. paksoft より:

    Hi dude,
    Great work, it works very well. I have one question for PWM mode. Can you please show me how to change the value at iOSC application of iPhone? So that that value received at arduino side can perform as PWM function.

    Regards,
    pak

  2. tamo より:

    Set “/osc/button1″ at “OSC Message” in “Button Setting” > “button on mes”.

    See at OSC Message:
    http://recotana.com/iphone/iosc/en/detail.html

  3. benji より:

    very very very cool

コメントをどうぞ

© 2017 samurai-apps. All rights reserved. Powered by WordPress Entries RSS Comments RSS