Arduino developer known as Krulkip sent me this little article along with Arduino sketch and video clip. To fit it into the blog I had to do some reformatting; what follows is Krulkip’s article – enjoy!
The webmail-notifier from Dreamcheeky is advertised as follows:
The WebMail Notifier has pretty light and optional sound alert software to tell you when you have email on one or all of your accounts, including Facebook. Dream Cheeky did what we do best with this product… helping you be more unproductive at the office. Now when you sneak off to the bathroom to check personal emails on your Blackberry, your trip will definitely not be wasted.
WebMail Notifier supports: Gmail, Yahoo, Outlook Express, POP3, Weibo, Facebook, Twitter, etc.
I wanted to control the Webmail Notifier from an arduino. As this is a USB device i needed to use the usb-host-shield manufactured by circuitsahome. With a little help from Oleg from circuitsathome and with the windows program from Frederic Delhoume i finally managed to get it working. What was needed was to send the unit two initialization sequences:
init1[7] = { 0x1F, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×03 };
init2[7] = { 0×00, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×04 };
Then you send the colour code eg:
msg3[7] = { 0xFF, 0xFF, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };
As Oleg explains “To write to HID device you either need an OUT endpoint or write to control endpoint.” In the end i used the Usb.setReport command similar to that used in the keyboard example where the keyboard LEDs are turned on/off.
The first three bytes are the brightness and colour coding. RR GG BB. It has 0x3F brightness as higher values do not increase the brightness. Enclosed is the arduino software to get it working. At the moment its just a code to get it to cycle the colours as shown on the video. Obviously i later on want to get it to do something usefull like checking my mail or something.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | /* MAX3421E USB Host controller Mail Notifier demonstration */ // http://www.dreamcheeky.com/webmail-notifier #include <Spi.h> #include <Max3421e.h> #include <Usb.h> #include <Max_LCD.h> /* Mail Notifier data taken from configuration descriptor */ #define MailNotifier_ADDR 1 #define MailNotifier_EP 1 #define MailNotifier_IF 0 #define EP_MAXPKTSIZE 8 #define EP_POLL 0x0a EP_RECORD ep_record[ 1 ]; //endpoint record structure for the Mail Notifier MAX3421E Max; USB Usb; Max_LCD LCD; void setup() { Serial.begin( 9600 ); Serial.println("Start"); Max.powerOn(); delay( 200 ); } void loop() { Max.Task(); Usb.Task(); if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) { //wait for addressing state MailNotifier_init(); Usb.setUsbTaskState( USB_STATE_RUNNING ); } if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the Mail Notifier MailNotifier_poll(); } } /* Initialize Mail Notifier */ void MailNotifier_init( void ) { byte rcode = 0; //return code /* Initialize data structures */ ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE; ep_record[ 1 ].Interval = EP_POLL; ep_record[ 1 ].sndToggle = bmSNDTOG0; ep_record[ 1 ].rcvToggle = bmRCVTOG0; Usb.setDevTableEntry( 1, ep_record ); //plug MailNotifier.endpoint parameters to devtable /* Configure device */ rcode = Usb.setConf( MailNotifier_ADDR, 0, 0x1F ); // byte addr, byte ep, byte conf_value, unsigned int nak_limit if( rcode ) { Serial.print("Error attempting to configure keyboard. Return code :"); Serial.println( rcode, HEX ); while(1); //stop } /* Set boot protocol */ rcode = Usb.setProto( MailNotifier_ADDR, 0, 0, 0 ); // byte addr, byte ep, byte interface, byte protocol, unsigned int nak_limit if( rcode ) { Serial.print("Error attempting to configure boot protocol. Return code :"); Serial.println( rcode, HEX ); while( 1 ); //stop } delay(2000); Serial.println("Mail Notifier initialized"); } /* Poll Mail Notifier and update intensity colour */ void MailNotifier_poll( void ) { char init1[] = { 0x1F, 0x01, 0x25, 0x00, 0xC4, 0x00, 0x25, 0x03 }; char init2[] = { 0x00, 0x01, 0x25, 0x00, 0xC4, 0x00, 0x25, 0x04 }; char msg1[] = { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Red char msg2[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Green char msg3[] = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Yellow char msg4[] = { 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Blue char msg5[] = { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Magenta char msg6[] = { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Cyan char msg7[] = { 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//White char msg8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Off byte rcode = 0; //return code // byte addr, byte ep, unsigned int nbytes, byte interface, byte report_type, byte report_id, char* dataptr, unsigned int nak_limit rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, init1 ); delay(500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, init2 ); delay(500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg1 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg2 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg3 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg4 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg5 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg6 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg7 ); delay(1500); rcode = Usb.setReport( MailNotifier_ADDR,0x00,0x08,MailNotifier_IF,0x02,0x00, msg8 ); delay(1500); } |
Here are just some pictures and a short video of the program working:
![]() |
![]() |
![]() |
What is the Arduino 1.0-compatible USB Host Library replacement for setReport? This is only working for me using the legacy driver pre-1.0.
If you mean rev.2.0 of the library then it does support HID SetReport().
I just did some necessary adaptions to the code above, so that it now works with rev2.0 of the USB Host library and Arduino-1.0.1. With my Cheeky Mail, I also had to adjust some color codes to get proper colors. I’m using it with the Sparkfun USB Host Shield with an additional connection from D7 to RST, as suggested on the sparkfun project site.
Hope that is helpful.
/* MAX3421E USB Host controller Mail Notifier demonstration */
// http://www.dreamcheeky.com/webmail-notifier
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Mail Notifier data taken from configuration descriptor */
#define MailNotifier_IF 0
USB Usb;
HIDUniversal Hid(&Usb);
void setup() {
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
}
void loop() {
Usb.Task();
if (Usb.getUsbTaskState() == USB_STATE_RUNNING) { //poll the Mail Notifier
MailNotifier_poll();
}
}
/* Poll Mail Notifier and update intensity colour */
void MailNotifier_poll( void )
{
uint8_t init1[] = { 0x1F, 0x01, 0x25, 0x00, 0xC4, 0x00, 0x25, 0x03 };
uint8_t init2[] = { 0x00, 0x01, 0x25, 0x00, 0xC4, 0x00, 0x25, 0x04 };
uint8_t msg1[] = { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Red
uint8_t msg2[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Green
uint8_t msg3[] = { 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Yellow
uint8_t msg4[] = { 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Blue
uint8_t msg5[] = { 0x0F, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Magenta
uint8_t msg6[] = { 0x00, 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//Cyan
uint8_t msg7[] = { 0x0F, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x25, 0x05 };//White
uint8_t msg8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x05 };//Off
byte rcode = 0; //return code
//new syntax : uint8_t HID::SetReport( uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr )
//old syntax : byte setReport( byte addr, byte ep, unsigned int nbytes, byte interface, byte report_type, byte report_id, char* dataptr, unsigned int nak_limit = USB_NAK_LIMIT );
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, init1 );
delay(500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, init2 );
delay(500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg1 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg2 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg3 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg4 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg5 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg6 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg7 );
delay(1500);
rcode = Hid.SetReport( 0,MailNotifier_IF,0x02,0x0,0x08, msg8 );
delay(1500);
}
Hi!
I was trying to follow your new code for the new library to send a 64 bytes report to a calculator. When I sniff the USB I can see 0x00, 0x00 at the message start followed with the data. I wrote an application based on that and it works nice but I want to use the USB host shield now.
http://cl.ly/TZHS here is the USB Desc sketch output. Why are you using 0x08 as the report ID? I tried with all the possible combinations for the arguments, from 0 to 3 (ep, iface, etc).
Any little hint? 😀
can I use a hub and hook up 2 or 3 mail notifiers? I’d like to use them to notify me when my snail mail is delivered, and when my washer and dryer complete their cycle.
Should be possible; you’d have to use new library though since legacy one doesn’t support hubs.