1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

New XPID software for Arduino UNO/Mega and Sabertooth (with LCD !!)

Discussion in 'SimTools compatible interfaces' started by vthinsel, Apr 1, 2015.

  1. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Hello !!

    So I have decided to start a new thread beside the 2DOF seat mover thread I initiated in order to discuss the software setup. The idea was to use an arduino with a sabertooth module which is a setup that is more and more used. I used the great code from wanegain as a basis and I started to discuss with him (the PM thread is 8 pages long now... and still growing everyday :D )
    We decided to improve the current setup with a LCD device to monitor/debug the runtime environment, but then we added support for the sabertooth 2*32, and later on we added support for Arduino Mega. All that with a single code, whatever the sabertooth module / arduino board you select. The LCD has a menu driven interface to configure the various parameters.
    I tested on a UNO and a MEGA, both with sabertooth 2*32A (set to 115200 with MEGA and set to 38400 for UNO). The loop takes 0-1ms on MEGA and 2-3ms on UNO. Should work out-of-the-box also on Sabertooth 2*25A

    Main advantages of Arduino MEGA 2560:
    • 4 Serial UART, allowing 115200bps end-to-end (one used by USB, leaving 3 full COM ports for your design). This means we can achieve sub 1ms latency between SimEngine output and sabertooth input
    • LCD/Keypad Shield compatible
    • Lots of available pins (both digital and analog) to add a TM1638 dashboard for example :D
    • 256Kb flash / 8Kb SRAM / 5K EEPROM (versus 32/2/1 for a UNO)

    Main advantages of Sabertooth 2*32
    • USB port to configure/monitor
    • 115200 Serial packet mode (with CRC)
    • same price as 2*25 !!!
    • Intelligent user mode to implement specific behavior
    • Can absorb regenerative current using resistors
    Many many other features .....

    The "platinum" setup is of course with an Arduino Mega 2560 and a sabertooth 2*32 but others should behave well also

    The LCD will allow you to
    • edit all PID parameters for each DC motor
    • edit your pot min/max/deadzone values
    • edit your global deadzone
    • change the sabertooth type
    • Set standby values for each motor
    • Change number of reads done on pots (average system)
    • Reset EEPROM to default values (recommended for first time load)
    • Show in realtime the value sent by SimEngine, the PID value calculated and the pot value (as well as loop time)

    All parameters are written to EEPROM so they are persistent of course.

    The LCD/Keypad management requires some cycles (which takes 10ms roughly), so in normal condition it should be turned off. There is a switch to install to make the LCD silent (it will also shut down the backlight).
    An additional feature has also been added : a standby position can be forced by an additional switch. This will allow you to put you sim in a known position whatever happens

    Enough writing, here is a demo !



    The pinout to wire everything :

    Pin out of arduino UNO for Sabertooth
    --------------------------------------
    Pin 3 - Sabertooth S1
    Pin 2 - Switch to enable/disable LCD. Switch open => LCD ON. Switch closed to GND => LCD Off and backlight Off
    Pin 12 - Emergency switch to disable DC motors between. Switch open => Motors ON . Switch closed to GND => Motors to standby value
    Pin A1 - input of feedback pot positioning from motor 1. (5V,wiper,GND)
    Pin A2 - input of feedback pot positioning from motor 2. (5V,wiper,GND))

    Pin out of arduino MEGA for Sabertooth
    --------------------------------------
    Pin TX1 - Sabertooth S1 at 115200bps (serial packet mode)
    Pin TX2 - Debug output at 115200bps
    Pin 53 - Switch to enable/disable LCD. Switch open => LCD ON. Switch closed to GND => LCD and backlight Off
    Pin 52 - Emergency switch to disable DC motors between. Switch open => Motors ON . Switch closed to GND => Motors to standby value
    Pin A14 - input of feedback pot positioning from motor 1. (5V,wiper,GND)
    Pin A15 - input of feedback pot positioning from motor 2. (5V,wiper,GND)


    [​IMG]

    In addition, all grounds should be connected : sabertooth/arduino/any device (arduino scope for example)

    3 additional Arduino libraries are needed:
    - Sabertooth library
    - MenuBackend
    - EEPROMex

    For Sabertooth 2*32, configure additional parameters using describe software as shown in the video below, which also demonstrates the system reactivity



    From a bench point of view the PID response looks good to me, the deadzone works as expected. Now I'll really think to build the rig, as the software looks good and stable to me.

    Some other pics here

    Time to play a bit now !

    EDIT: version 3.13 online. This will be the last version with LCD support. Next one will be for TFT+touchscreen. I may update bugs in this version, but no more features will be added.


    EDIT: version 3.15 online. This is the TFT+touchscreen version. Should you choose this version, get also the XPID_SimTools_3.15_libraries.zip file otherwise you just need the XPID_Arduino_libraries.zip file

    EDIT: version 3.20 online and on github for further updates https://github.com/vthinsel/XPID. Use libraries in file XPID_SimTools_3.15_libraries.zip

    Attached Files:

    • Like Like x 9
    • Winner Winner x 7
    • Funny Funny x 1
    Last edited: Jul 4, 2017
  2. Pit

    Pit - - - - - - - - - - - - - - - - Gold Contributor

    Joined:
    Oct 2, 2013
    Messages:
    3,012
    Location:
    Switzerland
    Balance:
    30,439Coins
    Ratings:
    +3,089 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Congratulation! The Ard's are more and more growing up. Thank you for this new code and effort.
    • Agree Agree x 1
  3. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,236
    Location:
    Marseille - FRANCE
    Balance:
    20,963Coins
    Ratings:
    +2,089 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Very impressive!
    The link to this topic is added to the Arduino FAQ ;)
    • Like Like x 4
  4. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,046
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,974Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Impressive indeed!
  5. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,236
    Location:
    Marseille - FRANCE
    Balance:
    20,963Coins
    Ratings:
    +2,089 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    • Informative Informative x 1
  6. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    So far, so good with clones. I have ordered some from different vendors in HK, and I haven't experienced issues so far. Time will tell...
    I tried 3 Uno (some using the DIL, some using flat package), and also 3 Mega. All worked (except one Uno which I had to reflash the bootloader).
    The touch screen is nice, but I'll really move away from Uno, as it is quite limited in terms of memory. Especially with such a nice add-on as the TFT touch screen, code will tend to grow a lot....
    I'll post today the code and libs. No bug fixes done yesterday, behavior is good
    • Like Like x 2
    • Agree Agree x 1
    • Funny Funny x 1
  7. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Soooooooo....
    Version 3.11 is attached to the first post, and I'll keep editing it so the latest version is always on the first post.
    Feel free to give it a try and give feedback !
    • Like Like x 2
    • Funny Funny x 1
  8. momoclic

    momoclic Active Member

    Joined:
    Sep 23, 2014
    Messages:
    215
    Occupation:
    Retraité
    Location:
    Nantes - France
    Balance:
    2,761Coins
    Ratings:
    +116 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino
    Merci pour ce beau travail,
    J'envisageai de faire quelque choses de similaire avec une UNO et j'ai acquis pour ça une carte Ethernet, ton code sera probablement adaptable ?

    Thank you for this beautiful work,
    I plan to do something similar with UNO and an Ethernet card, your code will probably be adaptable?
  9. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Why do you want native ethernet ? To have ethernet between SimEngine and Arduino ? Better immunity across mong distance ?
    I played sometime ago with a Mega128 and an ethernet module based on a wiznet chip. It was really slow : managing a TCP/IP (or UDP/IP) stack is very time consuming especially for so low speed devices such as AVRs. Timing and lowest latency is key in such projects, so I wouldn't feel very comfortable with ethernet/Arduino combo (maybe an arduino zero would be better, ARM based). With a RS232/USB serial link we can reach 1-2ms latency with this code which is fair. A simple ping, which is ICMP protocol already takes a couple of milli secs. Not to mention the code/flash space used by the IP stack. Go for arduino mega !
    Beside this, the arduino communicates with the ethernet shield using SPI : a serial link :think
    If you want to stack shields, you must also make sure the LCD and Ethernet shield do not use the same pins. The LCD shield uses 7 digital + one analog. So there are not many left for another shield (not to mention the needed pins for sabertooth/pots/switches). Once more, the Mega would be a better option.
    Ethernet would be nice to manage a nice web page to configure the PID, and thus replace the keypad of the LCD. But it shouldn't impact the timing for the PID loops
    • Funny Funny x 1
  10. Blame73

    Blame73 Well-Known Member

    Joined:
    Nov 6, 2014
    Messages:
    1,213
    Location:
    Italy
    Balance:
    8,281Coins
    Ratings:
    +1,115 / 2 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    hey @vthinsel first of all congrats for your achievement! Really impressive!
    Second, could you tell me how to reflash the bootloader of an UNO? I had a problem with a clone one (out of three), too.
    Thanks
  11. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    • Funny Funny x 1
    • Useful Useful x 1
    Last edited: Apr 2, 2015
  12. momoclic

    momoclic Active Member

    Joined:
    Sep 23, 2014
    Messages:
    215
    Occupation:
    Retraité
    Location:
    Nantes - France
    Balance:
    2,761Coins
    Ratings:
    +116 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino
    Ne connaissant pas grand chose dans les micro-controleurs ce sont ces mêmes seuls arguments que j'aurais pu avancer.
    Merci pour l'info.

    Not knowing much in micro-controllers it is these only arguments I could move forward.
    Thank you for the info.
  13. momoclic

    momoclic Active Member

    Joined:
    Sep 23, 2014
    Messages:
    215
    Occupation:
    Retraité
    Location:
    Nantes - France
    Balance:
    2,761Coins
    Ratings:
    +116 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino
    Un autre élément (peut-être pas heureux ?) c'est la possibilité sur la carte Ethernet de mettre une micro-SDHC

    Another element (maybe not happy?) Is the ability of the Ethernet card to a micro SDHC
  14. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Yes, but they are exclusive. At a given time you can use either ethernet OR micro SD. This adds complexity to the code and adds overall slowness.
    • Funny Funny x 1
  15. momoclic

    momoclic Active Member

    Joined:
    Sep 23, 2014
    Messages:
    215
    Occupation:
    Retraité
    Location:
    Nantes - France
    Balance:
    2,761Coins
    Ratings:
    +116 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino
  16. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Here is a pic of the connections for an arduino Mega (except for the LCD shield )

    [​IMG]
    I'll also make the same for Arduino Uno
    • Like Like x 3
    • Funny Funny x 1
    • Useful Useful x 1
  17. Fabgen

    Fabgen Member

    Joined:
    Dec 1, 2014
    Messages:
    72
    Location:
    France
    Balance:
    574Coins
    Ratings:
    +56 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform
    Merci je vais peut être réussir a faire fonctionner mes smolka arduino uno et sabertooth 2*32 car je galère pas mal

    Thank you I can be a successful run my smolka arduino uno and sabertooth 2 * 32 because It's a little bit hard to do
  18. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    The LCD screen is usefull in such case for debugging. Can be done on serial link as well, especially with the Mega2560 but I haven't implemented that yet, only basic debugging: no real time values.
    First step is to get values from SimEngine (LCD can help), second is to get values from pots (LCD can help), third is to make sure commands are sent to sabertooth (you can hook the TX pin to a regular com port on your PC to see what commands are sent), fourth is to make sure the sabertooth is correctly configured.
    I'll post a sample of RS232 packets sent to sabertooth, for reference.
    Good luck !
    • Funny Funny x 1
  19. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    BTW, I can also write in french if needed but I'm lazyyyyy :p
    • Funny Funny x 2
  20. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Hi there !
    The rig construction is moving slowly but surely. I did some code updates which I'm currently testing, especially around the ADC conversion. In most codes around, the FASTADC mode is used. As a side effect, the measures are quite imprecise, requiring to read several times and make an average.
    With FASTADC and 8 reads, I came up with a fluctuating deadzone of 3-4, but sometimes some glitches of 5 to 10 !! In that case the control loop takes around 1ms.
    With FASTADC disabled, and sample time of 1, I get a solid deadzone of 2 ! The control loop takes also around 1ms (I should look at decimals, but anyway too much samples seems to impact PID calculation in a bad way if I understood correctly).
    The choice is one accurate read versus several "bad" reads.
    Could someone advise on the FASTADC and its presence/necessity in code ? Maybe related to the pot moving while being read ? Is the same true when using hall sensors ?

    Stay tuned for version 3.12 very soon ;)
    • Funny Funny x 1