Shop OBEX P1 Docs P2 Docs Learn Events
Ipod remote control using BS2 — Parallax Forums

Ipod remote control using BS2

Luis_PLuis_P Posts: 246
edited 2009-09-25 01:07 in BASIC Stamp
· I'm pulling my hair right now!!! How can I send the Apple accesory protocol using BS2? someone is doing this using arduino IC, the IC connected to the dock connector of the Ipod/Iphone can Play, Stop, next, previous and more using AAP talk (http://nuxx.net/wiki/Apple_Accessory_Protocol)
· I think the command is SEROUT but I need an example to understand
Here is the Arduino project (Use C+ ):
http://davidfindlay.org/weblog/files/2009_09_07_ipod_remote.php

· Please help me!

Luis
·

Comments

  • xanatosxanatos Posts: 1,120
    edited 2009-09-17 21:26
    I'm sorry I haven't had any experience with the AAP or implementing it - yet - but I do want to thatnk you for the excellent links you provided here. I have copied the information for future refrerence as I'm bound to be using it eventually! Very good info, thanks!

    Dave X
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-17 22:31
    You can't use the BS2 because the speed is too high (19200 Baud). The BS2 can send that fast, but not reliably receive that speed. Some of the other Stamp models can handle 19200 Baud, but most of the AAP usage is at 57600 Baud which none of the Stamps can reliably handle. You'd have to use a Propeller or maybe an SX to handle the protocol.

    Both the Propeller and the SX have the advantage that they're 3.3V devices (optional with the SX) and don't need the voltage conversion circuitry that the Stamps need.
    ·
  • KraZe_EyEKraZe_EyE Posts: 15
    edited 2009-09-21 17:01
    You need to show us the iPodSerial.h file. This is the file with all the timing and command information.

    The code you posted is just a loop that detects button presses and filters them, not too short / long.
    And depending on which button is pressed it sends a different text string through the data line. The text string is inside the ipodserial.h file
  • Luis_PLuis_P Posts: 246
    edited 2009-09-23 13:56
    Here is the·Iphone/Ipod code Arduino IC uses to comunicate with, but·Mike Green·said the Basic Stamp is too fast to do that? Do I have to cross to Arduino ?

    #include <WProgram.h>

    class iPodSerial
    {
    public:
    ····iPodSerial();

    ····/**
    ···· * Sets the serial port that the library will use to communicate with the iPod.
    ···· * This defaults to "Serial", i.e. the normal serial port.
    ···· */
    ····void setSerial(HardwareSerial &newiPodSerial);

    ····/**
    ···· * Sets the Print object to which debug messages will be directed.
    ···· * By default there isn't one ando debug messages are off.
    ···· */
    ····void setDebugPrint(Print &newDebugSerial);

    ····/**
    ···· * Type of the callback that can receive song title information.
    ···· * If you call this function mySongTitleHandler your function
    ···· * definition might look like:
    ···· *
    ···· * void mySongTitleHandler(const char *title)
    ···· * {
    ···· *·· // do something with the title we just got
    ···· * }
    ···· */
    ····typedef void SongTitleHandler(const char *title);

    ····/**
    ···· * Sets the callback that the library will call when it
    ···· * receives song title information back from the iPod.
    ···· * (Currently this would happen after you called askForPos().)
    ···· * Setting it overrides any previous handler.
    ···· */
    ····void setSongTitleHandler(SongTitleHandler newSongTitleHandler);

    ····/**
    ···· * Play status of the iPod.
    ···· * Used by TimeAndStatusHandler
    ···· */
    ····enum Status
    ····{
    ········STATUS_STOP = 0,
    ········STATUS_PLAYING = 1,
    ········STATUS_PAUSED = 2
    ····};

    ····/**
    ···· * Type of the callback that can receive time and status information.
    ···· * If you call this function myTimeAndStatusHandler your function
    ···· * definition might look like:
    ···· *
    ···· * void myTimeAndStatusHandler(unsigned long length, unsigned long elapsed, Status status)
    ···· * {
    ···· *·· // do something with the information we just got
    ···· * }
    ···· */
    ····typedef void TimeAndStatusHandler(unsigned long length, unsigned long elapsed, Status status);

    ····/**
    ···· * Sets the callback that the library will call when it
    ···· * receives time and status information back from the iPod.
    ···· * (Currently this would happen after you called askForPos().)
    ···· * Setting it overrides any previous handler.
    ···· */
    ····void setTimeAndStatusHandler(TimeAndStatusHandler newTimeAndStatusHandler);

    ····/**
    ···· * Type of the callback that can receive the current position in the
    ···· * current playlist.
    ···· * If you call this function myCurrentPositionHandler your function
    ···· * definition might look like:
    ···· *
    ···· * void myCurrentPositionHandler(unsigned long position)
    ···· * {
    ···· *·· // do something with the position information we just got
    ···· * }
    ···· *
    ···· * position is the index of the currently-playing track in the current playlist
    ···· */
    ····typedef void CurrentPositionHandler(unsigned long position);

    ····/**
    ···· * Sets the callback that the library will call when it
    ···· * receives current position information back from the iPod.
    ···· * (Currently this would happen after you called askForPos().)
    ···· * Setting it overrides any previous handler.
    ···· */
    ····void setCurrentPositionHandler(CurrentPositionHandler newCurrentPositionHandler);

    ····/**
    ···· * Sends the Simple Remote (Mode 2) 'play/pause button being pressed' command to the iPod.
    ···· */
    ····void sendPlay();

    ····/**
    ···· * Sends the Simple Remote (Mode 2) 'button released' command to the iPod.
    ···· */
    ····void sendRelease();

    ····/**
    ···· * Switches the iPod to Advanced Remote mode (Mode 4) and issues
    ···· * the following commands:
    ···· *
    ···· * get-title (0x20)
    ···· * get-time-and-status-info (0x1C)
    ···· * get-current-position-in-playlist (0x1E)
    ···· *
    ···· * If no callbacks have been registered for the responses for
    ···· * these commands, then nothing will happen when those responses
    ···· * come in: the library will parse them when its loop() method
    ···· * is called, and it will generate debug messages if debugging
    ···· * has been enabled, but the responses will otherwise be
    ···· * ignored.
    ···· *
    ···· * This function is really a proof-of-concept for Advanced Remote
    ···· * mode support. If you look at http://nuxx.net/wiki/Apple_Accessory_Protocol
    ···· * you will see there are many other commands that could/should be
    ···· * supported.
    ···· *
    ···· * Also, note that placing your iPod in Advanced Remote mode
    ···· * causes its display to change to the green check with the
    ···· * "OK to disconnect" message. If you disconnect your connector
    ···· * cable the iPod will stay in this mode, but it should go back
    ···· * to its normal mode after 30 seconds or so. If not you can
    ···· * power it off and back on to get it back into normal mode.
    ···· * There's a change-mode command but I haven't implemented it yet.
    ···· */
    ····void askForPos();

    ····/**
    ···· * Initializes the library.
    ···· * This method must be called in your sketch's setup() function.
    ···· * You should *not* call begin on the serial port that your
    ···· * iPod is connected to: the library will do that here since it
    ···· * knows what baud rate it wants to talk at.
    ···· */
    ····void setup();

    ····/**
    ···· * Checks for data coming in from the iPod and processes it if there is any.
    ···· * The library handles partial messages coming in from the iPod so it
    ···· * will buffer those chunks until it gets a complete message. Once a complete
    ···· * message (that the library understands) has been received it will process
    ···· * that message in here and call any callbacks that are applicable to that
    ···· * message and that have been configured.
    ···· */
    ····void loop();

    private: // attributes
    ····static const byte HEADER1 = 0xFF;
    ····static const byte HEADER2 = 0x55;

    ····static const byte MODE_SWITCHING_MODE = 0x00;
    ····static const byte SIMPLE_REMOTE_MODE = 0x02;
    ····static const byte ADVANCED_REMOTE_MODE = 0x04;
    ····static const byte PLAY_CMD_1 = 0x00;
    ····static const byte PLAY_CMD_2 = 0x01;
    ····static const byte BUTTON_RELEASED_CMD_1 = 0x00;
    ····static const byte BUTTON_RELEASED_CMD_2 = 0x00;
    ····static const int IPOD_SERIAL_RATE = 19200;
    ····static const byte CMD_SONG_TITLE = 0x20;
    ····static const byte CMD_TIME_AND_STATUS_INFO = 0x1C;
    ····static const byte CMD_CURRENT_POSITION = 0x1E;

    ····enum ReceiveState
    ····{
    ········WAITING_FOR_HEADER1,
    ········WAITING_FOR_HEADER2,
    ········WAITING_FOR_LENGTH,
    ········WAITING_FOR_DATA,
    ········WAITING_FOR_CHECKSUM
    ····};

    ····ReceiveState receiveState;
    ····byte dataSize;
    ····byte dataBuffer[noparse]/noparse][color=#009999]128[/color;
    ····byte *pData;
    ····byte checksum;

    ····HardwareSerial *pSerial;
    ····Print *pPrint;

    ····CurrentPositionHandler *pCurrentPositionHandler;
    ····SongTitleHandler *pSongTitleHandler;
    ····TimeAndStatusHandler *pTimeAndStatusHandler;

    private: // methods
    ····bool validChecksum(const byte actual);
    ····unsigned long endianConvert(const byte *p);
    ····void displayTime(const char *prefix, const unsigned long ms);
    ····void dumpReceive();
    ····void processData();
    ····void processResponse();
    ····void sendCommand(
    ········const byte mode,
    ········const byte cmdByte1,
    ········const byte cmdByte2);
    ····void sendCommandWithParam(
    ········const byte mode,
    ········const byte cmdByte1,
    ········const byte cmdByte2,
    ········const unsigned long param);
    };

    #endif // IPOD_SERIAL
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-24 16:36
    Hello,

    I did a quick search on Google and found a few people who have successfully sent commands using a BASIC Stamp. There are also numerous websites posting the protocol used. It appears that many commands will run at multiple baud rates. In any event you will need to convert the code you have to the equivalent BASIC Stamp code. I think it should be able to be done. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • Luis_PLuis_P Posts: 246
    edited 2009-09-24 17:26
    Mmmmm....· I did an extensive search on Google too and nobody has any code or communication between BS2 and Iphone/Iphone. Can you post a link to the sites you found?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-09-24 18:04
    Well, as a quick example here are some sites that referenced BS2 and iPod...I didn't have time to filter throgh them all now, but there is even a thread on these forums where someone was posting their progress talking to an iPod from a BS2.

    http://blog.makezine.com/archive/2005/12/breakout_dock_ipod_hello.html

    http://www.popsci.com/diy/article/2006-12/touchless-ipod-remote

    http://zedomax.com/blog/search/basic+stamp

    http://www.labcoding.com/generic/homecontrol-using-the-basic-stamp-web-or-ipod-controlled2/

    http://nashlincoln.com/fun/ipod.php

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • Larry~Larry~ Posts: 242
    edited 2009-09-24 18:40
    not sure if this link will work or not It is an article in Nuts & Volts Feburary 07 by TJ Byers and shows how to use rs232 and 19200 to 57.6 baud


    http://nutsvolts.texterity.com/nutsvolts/200702/?pg=54&pm=2&u1=friend
  • Luis_PLuis_P Posts: 246
    edited 2009-09-24 21:11
    The links gives you an idea what you can do, but I don't see nobody posting a demo using a parallax IC and communicating with the ipod/Iphone. But the Arduino can for sure.
  • Larry~Larry~ Posts: 242
    edited 2009-09-25 01:07
    Looks like this guy / person did it

    http://panocamera.com/2005/Blog Dec 21, 2005 0-35.html
Sign In or Register to comment.