Hi all,
This will be my first post on the forum as I need some advice and guidance. I have searched the forum but can't find a similar issue, if I missed it I do apologize.
I have and Arduino Uno which I use to read Data from a USB Barcode scanner (via USB Host Shield) this data I want to transmit via GSM on a HTTP GET to my webserver
Apart I can get both functions to work 100% but the moment I start stacking the shields and integrating the code things go weird.
The TX and RX pins are set to 4 and 5 on SIMCOM.
Below is my code.
#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.h>
//GSM board stuff
#include <SoftwareSerial.h>
#include "SIM900.h"
#include "inetGSM.h"
//Variables: Scanner
String barcode = "";
int j = 1;
boolean action = false;
InetGSM inet;
//Variables: GSM
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;
char tk[25] = "Arduino Hello..scanner";
char link[20] = "/ardu/go.php?go=";
char url[50];
int gsmPin = 9;
USB Usb;
USBHub Hub(&Usb); //I enable this line
HIDUniversal Hid(&Usb); //Add this line so that the barcode scanner will be recognized, I use "Hid" below
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key); // Add this line to print character in ASCII
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
static uint32_t next_time = 0; //watchdog
static uint8_t current_cursor = 0; //tracks current cursor position
//add barcode to variable
j++;
delay(5);
barcode = barcode+(char)key;
// key 19 is the end character
if(key == 19){
action = true;
}
};
KbdRptParser Prs;
void setup()
{
//*******************START GSM STUFF: Create url for GET
strcat(url, link);
strcat(url, tk);
//Serial connection.
Serial.begin(9600);
Serial.println("--- MODEM BOOTING UP ---");
pinMode(gsmPin, OUTPUT);
digitalWrite(gsmPin, LOW);
delay(1000);
digitalWrite(gsmPin,HIGH);
delay (2500);
digitalWrite(gsmPin, LOW);
delay (3500);
Serial.println("--- MODEM BOOTING COMPLETE ---");
delay(5000);
//Serial to GSM
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started){
Serial.println("\nSTARTING APN CONNECTION");
//----BELOW BIT CAUSES EVERYTHING TO FAIL
if (inet.attachGPRS("internet", "", ""))
Serial.println("status=ATTACHED");
else Serial.println("status=ERROR");
delay(1000);
//*Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
// NOTE: I HAVE NOT ADDED THE REST OF THE CONNECTION CODE AS IT FAILED ALREADY
//--------------------------------------
Serial.println("\nDONE");
}
//START USB STUFF
//Serial.begin( 115200 );
Serial.println("USB Start");
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
Hid.SetReportParser(0, (HIDReportParser*)&Prs); //Here I change "Keyboard" for "Hid"
delay( 200 );
//***********************************************************
}
void loop()
{
Usb.Task();
if(action)
{
barcode.trim();
Serial.println("\n");
Serial.println(barcode);
barcode = "";
i = 0;
//Serial.println("\n bcode:"+barcode);
//Serial.println("\n i:"+i);
action = false;
}
}
As I said any guidance would be appreciated.
Thanks.
Ferdi