Nokia lcd and servo interference

Dear Arduino community.

Recently I started a project which goal is to use an Arduino Leonardo to control one standard hobby servo, one gps module and one Nokia 5110 84x48 display.

At first I wired the gps and servo to the Leonardo and used the standard servo library to control the servo and the software serial to connect to the gps. This caused twitching in the servo, something I understood was because the interrupts from the software serial disturbed the pwm signals from the servo library. My fix for this was simply to connect the gps to the single hardware serialport of the Leonardo.

I then proceeded to connect the lcd to five of the Leonardo's digital pins (3, 4, 5, 6, 8 ), and used the lcd5110_graph library to interface to the lcd. To my surprise the twitching problem reappeared. After some additional reading it became clear to me that the 5110 lcd interfaced to the arduino with something similar to software serial which I assume caused these new twitchings.

As I was without further hardware serialports to alleviate this problem my next step was to see if I could control the servo differently, I then discovered the ServoTimer1(Arduino Playground - Servotimer1) library which uses an Arduino's internal timers to control the pwm signals. The library stated that it was outdated but still was useful for those with problems were the new servo library would interfere with other pieces of software. I quickly noticed however that it wouldn't compile, with the output at the end of this post.

As I don't possess the technical know-how to dissect this error I would very much appreciate help in figuring out if this is a Leonardo specific problem or if the library simply hasn't been updated (I'm running Arduino 1.0.5).

Also, would it be possible to control a servo in another way that is not disturbed by system interrupts? Would it be possible to control the servo through the hardware serial port? As the gps only occupies the Rx pin the Tx pin is available, albeit locked to 4800 baud.

A big thanks for reading all the way through and I am very grateful for any help I can get :).

Yours sincerely
Clashjay

/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp: In static member function 'static void ServoTimer1::seizeTimer1()':
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:39: error: 'clockCyclesPerMicrosecond' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:45: error: 'TIMSK' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:45: error: 'TICIE1' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp: In member function 'uint8_t ServoTimer1::attach(int)':
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:75: error: 'digitalWrite' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:76: error: 'OUTPUT' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:76: error: 'pinMode' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp: In member function 'void ServoTimer1::detach()':
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:101: error: 'INPUT' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:101: error: 'pinMode' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp: In member function 'void ServoTimer1::write(int)':
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:117: error: 'clockCyclesPerMicrosecond' was not declared in this scope

My fix for this was simply to connect the gps to the single hardware serialport of the Leonardo.

The Leonardo has two hardware serial ports - one via the USB cable and one via pins 0 and 1.

I then proceeded to connect the lcd to five of the Leonardo's digital pins (3, 4, 5, 6, 8 ), and used the lcd5110_graph library to interface to the lcd.

A link to the library would be useful. No sense guessing how it works when we could look at the code and know.

Have you updated the ServoTimer1 library to be compatible with 1.0.5? wiring.h needs to be replaced by Arduino.h, at a minimum.

Adding the Arduino.h got rid of most of the error messages, yet one part persists.

/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp: In static member function 'static void ServoTimer1::seizeTimer1()':
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:46: error: 'TIMSK' was not declared in this scope
/Users/jacobbjorkman/Documents/Arduino/libraries/ServoTimer1/ServoTimer1.cpp:46: error: 'TICIE1' was not declared in this scope

Which directs to this part in ServoTimer1.cpp:

#if defined(AVR_ATmega168)
TIMSK1 &= ~(_BV(OCIE1A) | _BV(OCIE1B) | _BV(TOIE1) );
#else
TIMSK &= ~(_BV(TICIE1) | _BV(OCIE1A) | _BV(OCIE1B) | _BV(TOIE1) );
#endif
SREG = oldSREG; // undo cli()

The error code only refers to the code in the #else statement which compiles for every processor except for the ATmega168, as I found while googling the ATmega 2560 (Arduino Mega) didn't work with this library either which is why I suspect the code is ATmega328 only. I'm thinking that adding something like below between the #if and #else should give compatability with the Leonardo as well, but I'll have to dig more into that in tomorrow as it's getting a bit late :sleeping:

#elif defined(AVR_ATmega32U4)
//appropriate timer references for the ATmega324U;

Thank you for your help :slight_smile: