fughilli 0 Posted June 18, 2013 Share Posted June 18, 2013 Hello all! I've got three new libraries to share with you! They are: An Arduino "Servo" library clone (StellarPad): Duplicates all of the functionality of the Arduino "Servo" library. Fully compatible with all existing sketches that use the Arduino "Servo" library. Based upon the Eigendreams servo library posted here a while back. Supports 8 servos as-is. Can be modified to do a heck of a lot more, but that is up to you to incorporate (at least for now -- update to come soon). An ultrasonic rangefinder library (StellarPad, easily modifiable to work with other Energia devices): Designed for the HC-SR04 rangefinder, about $5 on e-bay. Should also work with some other rangefinders, but I have not tested any others. That is, again, up to you (for now). Supports as many of them as you can fit on your I/O. A data smoother library (All Energia/Arduino supported devices): Inspired by the Arduino "smoothing" example by Tom Igoe. Allows the creation of "Smoother" objects that calculate running averages of raw data. "Smoother" is a template class and can be instantiated to work with int's, float's, long's, etc. All three libraries have their own examples, and the following is an example that incorporates the functionality of all of them (No comments, sorry! This one is pretty self-explanatory. See the library-specific examples for more details): #include <SonicRanger.h> #include <Smoother.h> #include <Servo.h> SonicRanger sr; Servo servo; Smoother<int, 10> ssmoother; boolean smoothing = false; void setup () { sr.attach(PE_1, PE_2); servo.attach(PF_1); pinMode(BLUE_LED, OUTPUT); digitalWrite(BLUE_LED, LOW); pinMode(PUSH2, INPUT); attachInterrupt(PUSH2, buttonISR, FALLING); } void loop () { float distance = sr.getDistance(INCHES); int processedDistance; if(distance > 0) { processedDistance = (int)(distance * 1000); processedDistance = constrain(processedDistance, 2000, 12000); if(smoothing) { ssmoother.pushValue(processedDistance); processedDistance = ssmoother.pullValue(); } servo.write(map(processedDistance, 2000, 12000, 0, 180)); } delay(50); } void buttonISR () { smoothing = !smoothing; digitalWrite(BLUE_LED, smoothing); } Video demonstration of the above example sketch: http://youtu.be/IViqIa4Rl9Y Enjoy! -K/Fughilli SonicRanger.zip Smoother.zip Servo.zip vladn, jcoronel, gmtii and 4 others 7 Quote Link to post Share on other sites
bluehash 1,581 Posted June 18, 2013 Share Posted June 18, 2013 Lovely. Thank for sharing! If you would like to test some sensors, let me know. I'll see if I can sponsor you some hardware. fughilli 1 Quote Link to post Share on other sites
jcoronel 0 Posted September 7, 2013 Share Posted September 7, 2013 First of all, thanks for sharing! I've been playing with Servo library and it works very well, but if I use the function delayMicroseconds it stops working. Have you experienced the same problem? As far as I can see delayMicroseconds uses Timer4 and Servo library uses Timer2... What's wrong? Quote Link to post Share on other sites
jcoronel 0 Posted September 7, 2013 Share Posted September 7, 2013 First of all, thanks for sharing! I've been playing with Servo library and it works very well, but if I use the function delayMicroseconds it stops working. Have you experienced the same problem? As far as I can see delayMicroseconds uses Timer4 and Servo library uses Timer2... What's wrong? I have just tried to change Servo.h to use Timer 1 instead of Timer 4 and also modified startup_gcc.c acordingly and it work perfectly!. I don't know the reason why this works and the original configuration didn't worked. I'll do a little research about this issue... Quote Link to post Share on other sites
fughilli 0 Posted September 10, 2013 Author Share Posted September 10, 2013 Hmm. That's an interesting issue. I will investigate as well, but I personally haven't had any issues between delayMicroseconds() and the servo library. I wrote these three libraries and the Chronos library for a quadcopter project I am working on, and they all play nicely with one another, including delays and the other built-in library functions. Thanks for bringing my attention to the problem! -K/Fughilli Quote Link to post Share on other sites
jcoronel 0 Posted September 21, 2013 Share Posted September 21, 2013 I've been working arround this issue.I was confused about the problem. It hasn't to do with delayMicroseconds(), but with analogWrite().Maybe analogWrite is writing some register that stops TIMER2 and, hence, stops servo library. I'm going to check this hipothesis and I will post my results here. By the way, attached you can find the startup_gcc.c file adapted for Energia-0101E0010 version. Bye startup_gcc.c Quote Link to post Share on other sites
jcoronel 0 Posted September 21, 2013 Share Posted September 21, 2013 I found the explication for this issue! After digging in the code of Energia, I found that depending on the pin you write using analogWrite(), the microcontroller uses its corresponding TIMER, even if you have attached ant INT in startup_gcc.c. The only way to get all this working is to avoid using analogWrite() on any pin that is related to TIMER2. You may be wondering: where can I find that data? Here is: const uint8_t digital_pin_to_timer[] = { NOT_ON_TIMER, /* dummy */ NOT_ON_TIMER, /* 1 - 3.3V */ T1B0, /* 2 - PB5 */ T2A0, /* 3 - PB0 */ T2B, /* 4 - PB1 */ NOT_ON_TIMER, /* 5 - PE4 */ NOT_ON_TIMER, /* 6 - PE5 */ T1A0, /* 7 - PB4 */ NOT_ON_TIMER, /* 8 - PA5 */ NOT_ON_TIMER, /* 9 - PA6 */ NOT_ON_TIMER, /* 10 - PA7 */ NOT_ON_TIMER, /* 11 - PA2 */ NOT_ON_TIMER, /* 12 - PA3 */ NOT_ON_TIMER, /* 13 - PA4 */ T0A0, /* 14 - PB6 */ T0B0, /* 15 - PB7 */ NOT_ON_TIMER, /* 16 - RST */ T0A1, /* 17 - PF0 */ NOT_ON_TIMER, /* 18 - PE0 */ T3A, /* 19 - PB2 */ NOT_ON_TIMER, /* 20 - GND */ NOT_ON_TIMER, /* 21 - VBUS */ NOT_ON_TIMER, /* 22 - GND */ WT2A, /* 23 - PD0 */ WT2B, /* 24 - PD1 */ WT3A, /* 25 - PD2 */ WT3B, /* 26 - PD3 */ NOT_ON_TIMER, /* 27 - PE1 */ NOT_ON_TIMER, /* 28 - PE2 */ NOT_ON_TIMER, /* 29 - PE3 */ T0B1, /* 30 - PF1 */ T2A1, /* 31 - PF4 */ WT5B, /* 32 - PD7 */ WT5A, /* 33 - PD6 */ WT1B, /* 34 - PC7 */ WT1A, /* 35 - PC6 */ WT0B, /* 36 - PC5 */ WT0A, /* 37 - PC4 */ T3B, /* 38 - PB3 */ T1B1, /* 39 - PF3 */ T1A1, /* 40 - PF2 */ This is a fragment of the file pins_energia.h that you can find in <energia_directory>/hardware/lm4f/variants/stellarpad (if you are a Windows user change / for \). I was using one of the TIMER2 related pins, so after doing an analogWrite to that pin, my servo stopped responding. Quote Link to post Share on other sites
seewil13 0 Posted December 20, 2013 Share Posted December 20, 2013 Hi all, I'm very new to working with using new libraries in energia. I'm using the tiva c series eval kit - TM4C123GXL. And when I go to include the SonicRanger.h library I get many errors similar to the following: C:\Users\Connor\Desktop\energia-0101E0011\hardware\lm4f\cores\lm4f\driverlib/fpu.h:99:37: error: unknown type name 'uint32_t' C:\Users\Connor\Desktop\energia-0101E0011\hardware\lm4f\cores\lm4f\driverlib/gpio.h:166:47: error: unknown type name 'uint8_t' and I also am getting the error: C:\Users\Connor\Desktop\energia-0101E0011\hardware\lm4f\cores\lm4f\HC_SR04.c:70:16: error: 'INT_TIMER0A_' undeclared (first use in this function) C:\Users\Connor\Desktop\energia-0101E0011\hardware\lm4f\cores\lm4f\HC_SR04.c:86:35: error: unknown type name 'tBoolean' C:\Users\Connor\Desktop\energia-0101E0011\hardware\lm4f\cores\lm4f\HC_SR04.c:38:12: error: 'INT_GPIOE_' undeclared (first use in this function) I'm also getting several warnings about implicit declarations of various functions. I get these errors while executing the following code (it only is the includes): #include <Energia.h> #include <SonicRanger.h> void setup() { } void loop() { } Just wondering what I can do to try to get this library working? Thanks in advance for the help, Connor Quote Link to post Share on other sites
joelfinkle 1 Posted December 24, 2013 Share Posted December 24, 2013 I tried the sweep example that came with the servo library, and while it compiles, I doesn't do anything on upload. It's a mini servo that came with a Radio Shack "Arduino Starter Kit", brown wire to ground, red wire to VBUS, yellow to PF_1, using a Tiva board. Any suggestions? I don't have any other way to verify if the servo works. Quote Link to post Share on other sites
bluehash 1,581 Posted December 26, 2013 Share Posted December 26, 2013 I tried the sweep example that came with the servo library, and while it compiles, I doesn't do anything on upload. It's a mini servo that came with a Radio Shack "Arduino Starter Kit", brown wire to ground, red wire to VBUS, yellow to PF_1, using a Tiva board. Any suggestions? I don't have any other way to verify if the servo works. Did you select the correct board from the menu? Quote Link to post Share on other sites
joelfinkle 1 Posted December 26, 2013 Share Posted December 26, 2013 Did you select the correct board from the menu? Yes, the Tiva-C, using Energia 0101E0011. Quote Link to post Share on other sites
L.R.A 78 Posted January 2, 2014 Share Posted January 2, 2014 I'm realy interested in the servo one. Gona do some testing. A friend had one library that we used for it but for some reason, using analogWrite (in other pins, no the servo pins) would make the servos go crazy Quote Link to post Share on other sites
vladn 3 Posted March 14, 2014 Share Posted March 14, 2014 Hi. I am new to this forum. I am trying to download the servo library (from the first post in this thread) but getting the message: "You do not have permission to view this attachment" . What am I doing wrong ? I tried to contact admin twice but got no response yet. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.