MakeBlock,
You mean the USB WIFI receiver module that is shipped with every WIFI gamepad to enable the wireless gamepad to be connected to laptops and other devices via the USB port? yes, kinda of the first thing I checked.
Look, I understand the ME USB Host module uses the CH375B chip as explained in the product description.
Since the Orion is basically an Arduino UNO and the ME USB Host module is basically a CH376B breakout board, it stands to reason I should be able to use a stock arduino sketch to interrogate the ME USB Host board via the Arduino Serial Monitor to check it is sending and receiving ok?
This site HERE talks about the CH375B chip - it has a sketch for reading and writing to a USB key, but it includes features to talk to the chip and solicit reponses, unfortunately my skill skill isnt sufficient to determine whether I’ve got all the key elements correct, but maybe you can check the code below and tell me;
-
Are the pin settings correct.
-
What the baud rate should be for the ME USB Host board.
-
How the code below should be modified to put raw data from the connected gamepad
The point of the code below is to perform an isolation test which bypasses the MakeBlock library entirely and only test the MakeBlock hardware using 3rd party code.
/* ===============================================================
Project: CH376S USB Read/Write Module testing ground
Author: Scott C
Created: 1st May 2015
Arduino IDE: 1.6.2
Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html
Description: This project will allow you to perform many of the functions available on the CH376S module.
Checking connection to the module, putting the module into USB mode, resetting the module,
reading, writing, appending text to files on the USB stick. This is very useful alternative to
SD card modules, plus it doesn’t need any libraries.
================================================================== */
#include <SoftwareSerial.h>
byte computerByte; //used to store data coming from the computer
byte USB_Byte; //used to store data coming from the USB stick
int timeOut = 2000; //TimeOut is 2 seconds. This is the amount of time you wish to wait for a response from the CH376S module.
SoftwareSerial USB(13, 12); // RX, TX
//==============================================================================================================================================
void setup() {
Serial.begin(9600); // Setup serial communication with the computer (using a baud rate of 9600 on serial monitor)
USB.begin(9600); // Setup serial communication with the CH376S module (using the default baud rate of 9600)
}
//================================================================================================================================================
void loop() {
if(Serial.available()){
computerByte = Serial.read(); //read any incoming bytes from the Serial monitor, and store this byte in the variable called computerByte
if(computerByte==49){ //1 //If you send the number 1 from the serial monitor, the arduino will read it as digital number 49. Google "ascii table" for more info.
printCommandHeader("COMMAND1: CHECK CONNECTION");
checkConnection(0x01); // Check for successful connection and communication with the CH376S module.
}
if(computerByte==50){ //2
printCommandHeader("COMMAND2: set_USB_Mode");
set_USB_Mode(0x06); // Code used to enable read/write communication and monitoring of the USB stick
}
if(computerByte==51){ //3
printCommandHeader("COMMAND3: resetALL");
resetALL(); // Reset the USB device
}
}
if(USB.available()){ // This is here to capture any unexpected data transmitted by the CH376S module
Serial.print("CH376S has just sent this code:");
Serial.println(USB.read(), HEX);
}
}
//END OF LOOP FUNCTION ========================================================================================================================================
//print Command header
void printCommandHeader(String header){
Serial.println("======================");
Serial.println("");
Serial.println(header);
Serial.println("----------------------");
}
//checkConnection==================================================================================
//This function is used to check for successful communication with the CH376S module. This is not dependant of the presence of a USB stick.
//Send any value between 0 to 255, and the CH376S module will return a number = 255 - value.
void checkConnection(byte value){
USB.write(0x57);
USB.write(0xAB);
USB.write(0x06);
USB.write(value);
if(waitForResponse("checking connection")){ //wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.
if(getResponseFromUSB()==(255-value)){
Serial.println(">Connection to CH376S was successful.");
} else {
Serial.print(">Connection to CH376S - FAILED.");
}
}
}
//set_USB_Mode=====================================================================================
//Make sure that the USB is inserted when using 0x06 as the value in this specific code sequence
void set_USB_Mode (byte value){
USB.write(0x57);
USB.write(0xAB);
USB.write(0x15);
USB.write(value);
delay(20);
if(USB.available()){
USB_Byte=USB.read();
//Check to see if the command has been successfully transmitted and acknowledged.
if(USB_Byte==0x51){ // If true - the CH376S has acknowledged the command.
Serial.println("set_USB_Mode command acknowledged"); //The CH376S will now check and monitor the USB port
USB_Byte = USB.read();
//Check to see if the USB stick is connected or not.
if(USB_Byte==0x15){ // If true - there is a USB stick connected
Serial.println("USB is present");
} else {
Serial.print("USB Not present. Error code:"); // If the USB is not connected - it should return an Error code = FFH
Serial.print(USB_Byte, HEX);
Serial.println("H");
}
} else {
Serial.print("CH3765 error! Error code:");
Serial.print(USB_Byte, HEX);
Serial.println("H");
}
}
delay(20);
}
//resetALL=========================================================================================
//This will perform a hardware reset of the CH376S module - which usually takes about 35 msecs =====
void resetALL(){
USB.write(0x57);
USB.write(0xAB);
USB.write(0x05);
Serial.println("The CH376S module has been reset !");
delay(200);
}
//diskConnectionStatus================================================================================
//Check the disk connection status
void diskConnectionStatus(){
Serial.println("Checking USB disk connection status");
USB.write(0x57);
USB.write(0xAB);
USB.write(0x30);
if(waitForResponse("Connecting to USB disk")){ //wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.
if(getResponseFromUSB()==0x14){ //CH376S will send 0x14 if this command was successful
Serial.println(">Connection to USB OK");
} else {
Serial.print(">Connection to USB - FAILED.");
}
}
}
//USBdiskMount========================================================================================
//initialise the USB disk and check that it is ready - this process is required if you want to find the manufacturing information of the USB disk
void USBdiskMount(){
Serial.println("Mounting USB disk");
USB.write(0x57);
USB.write(0xAB);
USB.write(0x31);
if(waitForResponse("mounting USB disk")){ //wait for a response from the CH376S. If CH376S responds, it will be true. If it times out, it will be false.
if(getResponseFromUSB()==0x14){ //CH376S will send 0x14 if this command was successful
Serial.println(">USB Mounted - OK");
} else {
Serial.print(">Failed to Mount USB disk.");
}
}
}
//waitForResponse===================================================================================
//is used to wait for a response from USB. Returns true when bytes become available, false if it times out.
boolean waitForResponse(String errorMsg){
boolean bytesAvailable = true;
int counter=0;
while(!USB.available()){ //wait for CH376S to verify command
delay(1);
counter++;
if(counter>timeOut){
Serial.print("TimeOut waiting for response: Error while: ");
Serial.println(errorMsg);
bytesAvailable = false;
break;
}
}
delay(1);
return(bytesAvailable);
}
//getResponseFromUSB================================================================================
//is used to get any error codes or messages from the CH376S module (in response to certain commands)
byte getResponseFromUSB(){
byte response = byte(0x00);
if (USB.available()){
response = USB.read();
}
return(response);
}
regards
Michael