Loading...
Pages: [1]   Go Down
Author Topic: Usb-host shield problem  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Tampere, Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just bought usb-host shield (sparkfun) and arduino duemilanove and try compile board_test.pde code examples from http://github.com/felis/USB_Host_Shield, but i get error like this:
Code:
In file included from C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp:3:
C:\arduino\arduino-0020\libraries\USB_Host_Shield\/Max3421e.h:11: error: expected class-name before '{' token
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static void MAX3421E::regWr(byte, byte)':
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp:49: error: 'Spi' was not declared in this scope
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp: In member function 'char* MAX3421E::bytesWr(byte, byte, char*)':
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp:58: error: 'Spi' was not declared in this scope
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp: In member function 'byte MAX3421E::regRd(byte)':
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp:83: error: 'Spi' was not declared in this scope
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp: In member function 'char* MAX3421E::bytesRd(byte, byte, char*)':
C:\arduino\arduino-0020\libraries\USB_Host_Shield\Max3421e.cpp:93: error: 'Spi' was not declared in this scope

Can someone tell me what did I do wrong or post working example for me?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 271
Posts: 25422
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like you have forgotten to install all the libraries you need.
Logged

Tampere, Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I figure out what was problem. There was some typos in example code.
Is there any better ide than arduino ide?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 271
Posts: 25422
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any better ide than arduino ide?

No it's the very best there is for the arduino.
Logged

Tampere, Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grumpy_Mike thanks for your advise.

I'd be more than happy if someone would make working example how to read data from USB port in USB host shield.
I think i have a problem with spi and max3421e libraries.

I use:
arduino 0020
Arduino Duemilanove
USB Host Shield: (http://www.sparkfun.com/commerce/product_info.php?products_id=9628)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 271
Posts: 25422
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'd be more than happy if someone would make working example how to read data from USB port in USB host shield.

Sadly it is not as simple as that. The USB can be connected to a wide number of devices so you have to specify what sort of device you want to read data from.
Logged

Tampere, Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My project final goal is to get arduino communicate with nokia s60 phone.
First i'd like to get same data from usb hid device like usb mouse.
I tried this from http://www.circuitsathome.com:
Code:
/* Mouse communication via control endpoint */
#include <spi.h>
#include <max3421e.h>
#include <usb.h>
 
#define DEVADDR 1
#define CONFVALUE 1
 
void setup();
void loop();
 
MAX3421E Max;
USB Usb;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
    Max.powerOn();
    delay( 200 );
}
 
void loop()
{
 byte rcode;
    Max.Task();
    Usb.Task();
    if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
        mouse0_init();
    }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING...
    if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) {  //poll the keyboard
        rcode = mouse0_poll();
        if( rcode ) {
          Serial.print("Mouse Poll Error: ");
          Serial.println( rcode, HEX );
        }//if( rcode...
    }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING...
}
/* Initialize mouse */
void mouse0_init( void )
{
 byte rcode = 0;  //return code
  /**/
  Usb.setDevTableEntry( 1, Usb.getDevTableEntry( 0,0 ) );              //copy device 0 endpoint information to device 1
  /* Configure device */
  rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
  if( rcode ) {
    Serial.print("Error configuring mouse. Return code : ");
    Serial.println( rcode, HEX );
    while(1);  //stop
  }//if( rcode...
  Usb.setUsbTaskState( USB_STATE_RUNNING );
  return;
}
/* Poll mouse using Get Report and print result */
byte mouse0_poll( void )
{
  byte rcode,i;
  char buf[ 4 ] = { 0 };      //mouse buffer
  static char old_buf[ 4 ] = { 0 };  //last poll
    /* poll mouse */
    rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
    if( rcode ) {  //error
      return( rcode );
    }
    for( i = 0; i < 4; i++) {  //check for new information
      if( buf[ i ] != old_buf[ i ] ) { //new info in buffer
        break;
      }
    }
    if( i == 4 ) {
      return( 0 );  //all bytes are the same
    }
    /* print buffer */
    if( buf[ 0 ] & 0x01 ) {
      Serial.print("Button1 pressed ");
    }
    if( buf[ 0 ] & 0x02 ) {
      Serial.print("Button2 pressed ");
    }
    if( buf[ 0 ] & 0x04 ) {
      Serial.print("Button3 pressed ");
    }
    Serial.println("");
    Serial.print("X-axis: ");
    Serial.println( buf[ 1 ], DEC);
    Serial.print("Y-axis: ");
    Serial.println( buf[ 2 ], DEC);
    Serial.print("Wheel: ");
    Serial.println( buf[ 3 ], DEC);
    for( i = 0; i < 4; i++ ) {
      old_buf[ i ] = buf[ i ];  //copy buffer
    }
    Serial.println("");
    return( rcode );
}

but i don't get power into my usb mouse.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 271
Posts: 25422
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but i don't get power into my usb mouse.

That has nothing to do with the code, power is transferred by the wiring of your USB socket and is not under program control. What hardware are you using?
Logged

Tampere, Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I use:
arduino 0020
Arduino Duemilanove
USB Host Shield: (http://www.sparkfun.com/commerce/product_info.php?products_id=9628)
USB Host Shield Power LED lights up when turn on switch but  usb port in shield dosn't give power.



Quote
That has nothing to do with the code, power is transferred by the wiring of your USB socket and is not under program control.
I think this turn power on.
Code:
Max.powerOn();

but that function doesn't  return at all.
Logged

Pages: [1]   Go Up
Print
 
Jump to: