Using iPad with mbed for software development?

24 Mar 2012

Has anyone been able to use an iPad for software development and code download with mbed?

I have some students that were asking about it and they wanted instructions.

I noticed that the Apple iPad Camera? adapter connector is really USB and some people say that it works with some USB flash drives and a few other USB devices. There is a video showing how to mount a USB flash drive, but it looks ugly. Don't have one to try.

Would probably be too lucky, if a USB virtual com port would also work somehow for printf().

29 Mar 2012

Apple has blocked the USB camera adapter on the software side. There was a hack, but you have to jailbreak the device. I'm not shure if this works with the actual IOS.

30 Mar 2012

I managed to get comms working on the serial pins and the mbed, but this was with a jailbroken iphone ios 2.1 . You need to become MFI (made for ipod) to gain real access and use the support APIs. I tried but failed to get approval :/ . So I moved to Android :)

#include "mbed.h"
#include "iPhoneSerial.h"

iPhoneSerial::iPhoneSerial( PinName tx, PinName rx, PinName gnd, int baudrate) : _iphone(  tx,  rx ) , _iphoneGND(gnd) {

    m_buffSize = 0;
    m_contentStart = 0;
    m_contentEnd = 0;
    m_timeout = 1.0;

    m_buff = (uint8_t *) malloc( 64 );
    if ( m_buff == NULL ) {
        //loggerSerial.printf("SerialBuffered - failed to alloc buffer size %d\r\n", (int) bufferSize );
    } else {
        m_buffSize = 64;
    }


    _handshake = '*';
    _iphone.baud(baudrate);

    _iphoneGND = 1; //enable gound to iphone

    //_iphone.attach(this,&iPhoneSerial::read);
    _iphone.attach( this, &iPhoneSerial::handleInterrupt, Serial::RxIrq);

}

iPhoneSerial::~iPhoneSerial() {
    if ( m_buff )
        free( m_buff );
}

void iPhoneSerial::setTimeout( float seconds ) {
    m_timeout = seconds;
}

uint8_t* iPhoneSerial::getBuffer() {

    return m_buff;
}


int iPhoneSerial::readable() {
    return m_contentStart != m_contentEnd ;
}

void iPhoneSerial::attach(void (*fptr)(void), char c) {
    c1 = c;
    fptr1 = fptr;
}

void iPhoneSerial::handleInterrupt() {

    while ( _iphone.readable()) {

        uint8_t byte = _iphone.getc();

        if (!connected) {

            if (byte==_handshake) { // Check if this byte is a "handshaking" message {
                printf("\n\rStrobing %0x - %d - %c ", byte,byte,byte);
                strobeGround();
                _iphone.putc(_handshake);
;

                //assume iphone handshake worked!
                connected=1;
            }

        } else {

            if ( m_contentStart == (m_contentEnd +1) % m_buffSize) {
                //  serial.printf("SerialBuffered - buffer overrun, data lost!\r\n" );
                _iphone.getc();

            } else {



                if (byte == c1) {
                    byte = 0;

                    m_buff[ m_contentEnd ++ ] = byte;
                    fptr1();
                    //reset
                    m_contentEnd = m_contentEnd % m_buffSize;
                    m_contentStart = 0;
                    m_contentEnd = 0;
                } else {
                    m_buff[ m_contentEnd ++ ] = byte;
                    m_contentEnd = m_contentEnd % m_buffSize;

                    //    serial.printf(" %d", m_buff[ m_contentEnd ] );
                }
            }
        }
    }
}

    void iPhoneSerial::read() {

        char   byte = _iphone.getc();

        if (!connected) {

            if (byte==_handshake) { // Check if this byte is a "handshaking" message {
                printf("\n\rStrobing %0x - %d - %c ", byte,byte,byte);
                strobeGround();
                _iphone.putc(_handshake);

                //assume iphone handshake worked!
                connected=1;
            }
        } else {
            // if connected then do and or attach methoid
            printf("\n\rAfter Connected %0x - %d - %c ", byte,byte,byte);
 
            if (byte == 0) {
                connected=0;
            }

            //test
            if (byte == 'I') {
                _iphone.putc('Z');
            }
           }
        }


    }

    void iPhoneSerial::putc(char c) {
        _iphone.putc(c);
    }

void iPhoneSerial::writeDouble(double  arg1) {
    char* pfD = (char*)&arg1;
    //char data[] = {pfD[0],pfD[1],pfD[2],pfD[3],pfD[4],pfD[5],pfD[6],pfD[7]};

    _iphone.putc(pfD[0]);
    _iphone.putc(pfD[1]);
    _iphone.putc(pfD[2]);
    _iphone.putc(pfD[3]);
    _iphone.putc(pfD[4]);
    _iphone.putc(pfD[5]);
    _iphone.putc(pfD[6]);
    _iphone.putc(pfD[7]);   
 
}

    char iPhoneSerial::getc() {
        return _iphone.getc();
    }


    void iPhoneSerial::strobeGround() {
        for (int i=0;i<10;i++) {
            _iphoneGND=!_iphoneGND;
            wait(.02);
        }
        _iphoneGND=1;
    }

See my first gen ipod working here

30 Mar 2012

I bought an inexpensive ANDROID tablet from Maplins,

it has 2 USB's micro USB as well as a MEMORY stick hole :)

and a uSD hole !!

AND there is lots of things you can stick in any ANDROID device,

but make sure you get a 'market place approved' device :)

Cheers

Ceri.