MIDI signal

MIDI signal in oscilloscope. Inverted serial 31200 bits per second. Captured from USB->MIDI adapter (SWIS). First bit time is about 32us (31.2us = microsecond ). Voltage difference was 3.92V.

A great page describing MIDI: http://www.tigoe.net/pcomp/code/serial-communication/midi which describes MIDI like:

“MIDI is a serial communications protocol, operating at 31,250 bits per second. Each byte has 8 bits, plus a start bit and a stop bit. It operates at 5 volts DC. The standard MIDI connector is a 5-pin DIN connector, and usually all connectors on the device are female, and both ends of a MIDI cable are male.”

From here http://home.roadrunner.com/~jgglatt/tech/midispec.htm :

  • MIDI is an asynchronous serial interface.
  • The baud rate is 31.25 Kbaud (+/- 1%).
  • There is 1 start bit, 8 data bits, and 1 stop bit (ie, 10 bits total), for a period of 320 microseconds per serial byte.
  • The MIDI circuit is current loop, 5 mA.
  • Logic 0 is current ON.
  • To avoid grounding loops and subsequent data errors, the input is opto-isolated. It requires less than 5 mA to turn on. The Sharp PC-900 and HP 6N138 optoisolators are satisfactory devices. Rise and fall time for the optoisolator should be less than 2 microseconds.
  • The standard connector used for MIDI is a 5 pin DIN.
  • Separate jacks (and cable runs) are used for input and output, clearly marked on a given device (ie, the MIDI IN and OUT are two separate DIN female panel mount jacks).
  • 50 feet is the recommended maximum cable length.
  • Cables are shielded twisted pair, with the shield connecting pin 2 at both ends.
  • The pair is pins 4 and 5. Pins 1 and 3 are not used, and should be left unconnected.

Working MD5 for Objective-C

  1.  
  2.  
  3. #import <CommonCrypto/CommonDigest.h>
  4.  
  5.  
  6. NSString * md5( NSString *str )
  7. {
  8.  
  9. const char *cStr = [str UTF8String];
  10.  
  11. unsigned char result[CC_MD5_DIGEST_LENGTH];
  12.  
  13. CC_MD5( cStr, strlen(cStr), result );
  14.  
  15. return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  16. result[0], result[1],
  17. result[2], result[3],
  18. result[4], result[5],
  19. result[6], result[7],
  20. result[8], result[9],
  21. result[10], result[11],
  22. result[12], result[13],
  23. result[14], result[15]];
  24.  
  25. }
  26.  
  27.  

Calculating distance in Objective-C

Returns distance in meters between to coordinates.

  1.  
  1. float calcDistance(float lat1, float lon1, float lat2,float lon2)
  2. {
  3.         float R = 6371; // km
  4.         float dLat = deg2rad((lat2-lat1));
  5.         float dLon = deg2rad((lon2-lon1));
  6.         float a = sin(dLat/2.0) *
  7. sin(dLat/2.0)+cos(deg2rad(lat1))*
  8. cos(deg2rad(lat2))*sin(dLon/2.0)*sin(dLon/2.0);
  9.         float c = 2.0 * atan2(sqrt(a), sqrt(1-a));
  10.         float d = R * c;
  11.  
  12.         return d*1000;
  13. }

Technology snippets