Saturday, December 13, 2014

pcDuino Libraries and Samples for 1Sheeld

It's been a while (a couple of years!) since I've posted to this blog.  But, it was time to share again ;)

I've been taking some time (on and off) recently to attempt to get the 1Sheeld to work with my pcDuino v2.   And I'm not talking about plugging in an UNO or Mega to a USB hub and connecting the 1Sheeld to the Arduino and using the Arduino IDE that's available on the pcDuino (although if you want to use OneSheeld sitting on a pcDuino using the Arduino IDE, see my other post regarding that).  If you are connecting an Arduino, putting the 1Sheeld on it, and using the Arduino IDE, just copy over the 1Sheeld Library/Examples as-needed and it will work as-is.   I'm talking about attaching the 1Sheeld to the pcDuino and using the pcDuino-native Aduino-ish libraries (c_environment) and getting it to work that way.   And I've been successful from what I can tell.   The biggest hurtle was input from the Android App to the pcDuino.   The bluetooth part worked fine, but the pcDuino NEVER received the Serial Input that it needed in order to proccess the messages.

 <<< TERMIO ISSUES >>>  
 You may want to add this somewhere to your start-up configuration ... 
 or create an easily accessible script somewhere.  
   
 stty -onlcr -icrnl -F /dev/ttyS1   
   
 If you don't, using some of the Shields won't work as-expected ... 
 and if you ever need to you can always do this to reset to default: 

 stty onlcr icrnl -F /dev/ttyS1  
   
 If you really want to make a code change ... you will have to modify
 the Serial.cpp module to add this somewhere in the begin function 
 (I tested with it right before the tcsetattr() call ...   
   
  Opt.c_iflag &= ~(ICRNL);   
  Opt.c_oflag &= ~(ONLCR);   
   
 There are a couple of shields that are affected if these changes aren't
 in place (Terminal and Internet Shields are known to have problems).  



I have placed all of the pcDuino compatible 1Sheeld code (and make files required to build) here (see below updates, things may have changed if you've downloaded before). 



If you extract/copy directly to the c_environment directory, you should be good to go (replace everything when prompted, if by chance you already have the pcDuino OneSheeld libraries and samples installed).

Now all you should need to do is change to the OneSheeld directory and  make clean, followed by a make to rebuild the OneSheeld library AND the samples.   You will see some warnings, but everything should build fine.  Now changing to the sample/bin/Simple or /Advanced directories and executing the sample(s) should allow you to test the 1Sheeld as-needed from pcDuino.  If everything goes well, you should be ready to build your own sketches.   Note: Unless you add the Simple and Advanced directories to your path, you will need to run them with a ./ before them (i.e. ./Keypad will execute the Keypad sample(s), etc).

I originally thought that a change was necessary to the pcDuino Serial.cpp module, but I have figured out a way to make everything work with just OneSheeld library changes, so the Serial.cpp module is now back to it's original version.

So, if you already had the pcDuino OneSheeld libraries, make sure you revert back to the original Serial.cpp module ... remove the comment tags that commented out the serialEvent() and serialEventRun() functions and delete the newer serialEventRun() function.

 /*  
 #define serialEvent_implemented  
 void serialEvent()  
 {  
   Serial.process_recv();  
 }  
   
 void serialEventRun(void)  
 {  
 #ifdef serialEvent_implemented  
   serialEvent();  
 #endif  
 }  
 */  
   
 void serialEventRun(void)  
 {  
  Serial.process_recv();  
  serialEvent();  
 }  

The primary changes to the OneSheeld code was to copy over a string handling function from Arduino (and include) that isn't part of the c_environment library ... add a timeout value to the pulseIn calls ... move a typedef unsigned char byte; higher in the OneSheeld.h (errors will occur if it's not there due to byte being undefined in pcDuino's Print.h module ... frankly, it would probably be better to just change the byte to an uint8_t, but I tried to keep the pcDuino code changes to a minimum),  added forward declarations to the samples that needed them and rename the sample sketches from .ino to .c ... pretty much it really.

MAKE ABSOLUTELY SURE that you set the voltage switch on the 1Sheeld to 3.3V rather than 5V since that's what pcDuino supports (unless you have the Translation T Board for bridging a 5V shield to 3.3V).    Also, just leave the other switch set to UART ... you don't need to worry about pcDuino needing the serial port for uploading a sketch ... it's already part of the file system and you execute it from there.

I haven't tried every single one of the OneSheeld Shield samples yet.   So, if you have some problems let me know.

Kudos to the developers at 1Sheeld and a lot of credit goes to them, most of their code was left as-is from the Arduino libraries/samples.   Very cool product.

Updates

12-25-2014 - pcDuino Libraries/Samples now coincide with v1.3 of the Arduino/Libraries.

12-26-2014 - Some cleanup, plus added the ARDUINO_LINUX and PCDUINO defines to the make file.  Allows most of the code to compile better as-is.  Since there's no HardwareSerial.h (or Serial1), some changes were made to the OneShield.cpp (now with #if defined(PCDUINO) and #if !defined(PCDUINO) checks) to #include "Serial.h" rather than "HardwareSerial.h" and use Serial rather than Serial1.   Also had to move the typedef for byte above the #include "Stream.h" so it would be available sooner.

12-27-2014 - I have revisted all of the samples again.  Decided to use forward declarations rather than moving the functions that required it.  This allows easier comparison of new versions when released by 1Sheeld.    Note:  I have also updated the main blog above to represent the latest.

01-10-2015 - I have changed the directory structure of the OneSheeld Libraries and Samples.  If you have previously downloaded, you may want to start by removing the output/testOneSheeld, libraries/OneSheeld and sampleOneSheeld directories as-well-as removing the OneSheeld.a/.so and MakeOneSheeld files from the c_enviroment directory ... then just extract the OneSheeld directory from the zip, put it in the c_enviroment directory and rebuild (go to the c_enviroment/OneSheeld directory, do a make clean followed by a make to do a full rebuild) ... if you haven't downloaded previously, make sure you also unzip and update the hardware directory included so that the Serial.cpp gets updated.

01-21-2015 - I have been creating Netduino 1Sheeld library/samples lately (will blog about it soon), but during that time, I found a problem with the Keypad Shield callback handling.  I have confirmed with the 1Sheeld folks that it is a problem.  So, the latest download now has a fix for that (.zip file has been updated on Google Drive). I also increased the size of the text for the link to the code so it stands out a bit more.

01-24-2015 - Found a small problem with the Temperature Sensor Shield code.  The getAsFahrenheit function should be returning fahrenheit, NOT value.   The code has been updated for pcDuino on Google Drive.

01-27-2015 - Found another small problem.  This time with callback handling on the GamePad Shield (basically the bool variables never got updated unless you also called the related get*Pressed function too (which frankly, the callback handling should be such that you would never have to do that). The code has been updated for pcDuino on Google Drive.

01-29-2015 - There was a small problem with year handling on the Clock Shield ... if, by chance, you were using the Clock Shield when the year changed (yeah, I know, doesn't happen very often), an unexpected value could be returned  for the year.   The code has been updated for pcDuino on Google Drive.

02-13-2015 - Moved Libraries and Samples from Google Drive to Github.

03-05-2015 - Removed Requirement to make changes to Serial.cpp ... now all required changes are part of the OneSheeld libraries (and samples).   Changes have been commited to Github.

03-09-2015 - pcDuino Libraries/Samples now coincide with v1.4 of the Arduino/Libraries.  Github has been updated.

03-19-2015 - update to fix JsonKeyChain.cpp module is now out on Github.  The Advanced Internet Sample will now work on pcDuinos (note the same changes need to also be made to the JsonKeyChain.cpp for the Arduino IDE (you could just copy the .cpp module to the OneSheeld library directory for the IDE is you wanted ... it's all the same code).

03-24-2015 - Minor changes updated on Github updates equivalent to the recently added to the Arduino Library.

05-06-2015 - Updated to v1.5.   Github has been updated.

08-19-2015 - Updated to v1.6.   Github has been updated.

09-21-2015 - Updated to v1.6.1.  Github has been updated.

11-30-2015 - Updated to v1.7.  Github has been updated.

01-27-2016 - Updated to v1.8.  Github has been updated.

04-22-2016 - Updated to v1.9.  Github has been updated.

05-24-2016 - Updated to v1.9.2 (I never did a v1.9.1 update).  Github has been updated.

12-11-2016 - Update to v1.10.  Github has been updated.

02-19-2017 - Update to v1.12 (never did a v1.11 update).  Github has been updated.

07-14-2017 - Update to v1.13.  GitHub has been updated.