App: Wixel in little robot powered by step motors

Support and community forum for the Wixel Programmable USB Wireless Module.

App: Wixel in little robot powered by step motors

Postby Perrotti » Thu Oct 25, 2012 11:35 pm

This is my first Wixel application, actually also my first experience with a microcontroller, so I had some difficulty to learn enough to make this program
and probably this is not the best code, but that's what I get at this time and apparently is working well.

I had a lot of help from this forum and want to thank David for his patience and fast and accurate answers. I'm putting this code to help the beginners and
perhaps also to receive suggestions from Wixel's masters circulating here.
Would be very welcome.

The application is relatively simple and involves a small robot powered by unipolar stepper motors taken from scrapped printers.


Computer calculates the setting of bits to enable pins connected to stepper motors and also calculates time for each pulse should last. For each pulse, two bytes are sent to Wixel, one for pin and one for pulse duration. Even robot moves few inches, may be needed hundreds of pulses. So, application implements a circular buffer capable to store 1024 pulses and makes necessary controls to send pulses to pins in correct sequence and duration.

According pulses will run, will be released in buffer space, so, computer can send more pulses, even as part of previous is still running.

In my case, duration of pulses ranges from 12ms (cruising speed) to 40ms (starting speed) so 1024 pulses means at least 12 seconds of robot's motion. That's enough time to computer prepare and send following pulses with enough slack.

The Wixel connected to computer has no processing other than relay messages exchanged between robot and computer. In future versions I'm considering changing it, might be used as second buffer or as auxiliary processor.

Below the source code. The program provides a simple messaging protocol between two ends. Messages are sent in packets with a head byte and a variable number of bytes to payload. The head byte uses 2 bits to inform message size and other 6 to message. So we can have 64 different messages and choose from 4 standard sizes.

Much of communication is done with messages that require no parameters, so message can have only head byte without payload.

main loop: a1Robot.c
Code: Select all Expand

some common defs: rbTypes.h

Code: Select all Expand

Small led control. Implements updateLeds function
Code: Select all Expand

Code: Select all Expand

Message protocol
Code: Select all Expand

Code: Select all Expand

Pack support
Code: Select all Expand

Code: Select all Expand

Pulse buffer and exec. pulseCheck() needs to be called frequently
Code: Select all Expand

Code: Select all Expand
Posts: 21
Joined: Sat Oct 06, 2012 6:30 pm

Re: App: Wixel in little robot powered by step motors

Postby DavidEGrayson » Fri Oct 26, 2012 8:46 am


I am glad that you have had success with the Wixel, and thank you for posting information about your project here! I was having trouble reliably loading your image from, so I copied it and uploaded it as an attachment to forum:

wixel_perrotti.png (566.05 KiB) Viewed 4437 times

Pololu Employee
Posts: 2763
Joined: Thu Apr 03, 2008 11:30 am
Location: Las Vegas, NV

Re: App: Wixel in little robot powered by step motors

Postby Michely » Sat Oct 27, 2012 5:40 am

Excellent job, congratulations!!!
Posts: 1
Joined: Sat Oct 27, 2012 5:37 am

Return to Wixel

Who is online

Users browsing this forum: No registered users and 0 guests