USB servo via trinket

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
unixnerd777
 
Posts: 29
Joined: Tue Jun 18, 2013 10:37 pm

USB servo via trinket

Post by unixnerd777 »

I got the 3V trinket yesterday and then realized the 8MHz vs 16MHz. I got the trinket to be a hardware volume knob, so I ordered the 16MHz trinket and am trying to use the 3V 8MHz as a USB servo controller (sorta a combination of http://learn.adafruit.com/trinket-fake-usb-serial and http://learn.adafruit.com/trinket-gemma-servo-control). Has anyone gotten the usb serial to work in linux (I would like to see an example of how exactly to use the python script mentioned in the guide). I was thinking of using http://www.servocity.com/html/spt200_pa ... ystem.html and http://www.servocity.com/html/hs-985mg_ ... orque.html -does anyone know of a cheaper solution?

At the very least, I need to be able to SSH over the internet and move it, defaulting to a wider shot if I loose connection. I will probably achieve this via dvgrab | tee >(ffmpeg -i - -qscale 10 disk_quality.mp4) >(ffmpeg -i - -an -s 300x300 -qscale 40 small.mp4 #for streaming). I intend to use OpenCV to track, but am having problems with background subtraction ATM (I have face detection working, but he tends to turn his head when he walks to the side, which it doesn't follow).

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: USB servo via trinket

Post by adafruit_support_mike »

unixnerd777 wrote:At the very least, I need to be able to SSH over the internet and move it, defaulting to a wider shot if I loose connection. I will probably achieve this via dvgrab | tee >(ffmpeg -i - -qscale 10 disk_quality.mp4) >(ffmpeg -i - -an -s 300x300 -qscale 40 small.mp4 #for streaming). I intend to use OpenCV to track, but am having problems with background subtraction ATM (I have face detection working, but he tends to turn his head when he walks to the side, which it doesn't follow).
You seem to have run ahead of your details. I have no idea what 'it' you're trying to control. You certainly won't be able to connect to a Trinket with ssh or run ffmpeg on it.. the microcontroller only has 8k of Flash memory and 512 bytes of RAM.

User avatar
unixnerd777
 
Posts: 29
Joined: Tue Jun 18, 2013 10:37 pm

Re: USB servo via trinket

Post by unixnerd777 »

I am trying to use the trinket as a bridge between a SSH-able linux system, and the servo (to control the servo over USB) I may also get another trinket to run a IR LED to control the camera's zoom.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: USB servo via trinket

Post by adafruit_support_mike »

Okay, that makes more sense. I take it you want to use the FakeUSB interface to send information from the Linux machine to the Trinket.

I don't recall any posts with people using the fake USB script on Linux, but that's usually a good thing. We mostly get conversations here in the forum when something /doesn't/ work as expected.

I'll send a note to Frank (who wrote that tutorial) and see if he can give you any advice.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: USB servo via trinket

Post by adafruit »

Any USB data requires 16mhz, so it wont work well on the 3V trinkets - that is considered overclocking. honestly, the USB-fake-serial is a bit of a hack, if you cant get it working (reliably) with a 5V trinket, go with an Arduino Micro :)

User avatar
frank26080115
 
Posts: 126
Joined: Fri Jun 15, 2007 1:04 am

Re: USB servo via trinket

Post by frank26080115 »

The tutorial does tell you how to use the script. Did you try it?

http://learn.adafruit.com/trinket-fake- ... -slash-mac

The steps were to install Python and all the required Python libraries that are needed. Then to setup the virtual bridge using the "socat" command. Then just run the Python script "TrinketFakeUsbSerialHostSW.py", then just start using Arduino like you normally would.

Try it out.

I'm not sure on how to provide more details in the instruction unless you give me specific questions or specific error messages to solve.

User avatar
frank26080115
 
Posts: 126
Joined: Fri Jun 15, 2007 1:04 am

Re: USB servo via trinket

Post by frank26080115 »

keep in mind that USB fake serial is designed for people who do not want to learn how to use USB properly

the majority of the setup process for the fake serial port involves... well... some hacked up solution that makes a fake serial port, this complexity in the installation is the trade off for simplicity in the usage.

you sound like the kind of guy who might benefit from using true USB protocols. a servo controller sounds like the kind of application that might benefit from using simple control request messages. You'll end up with better responsiveness, it will be less error prone, and it will take up less code space. This is because control requests have a defined structure. Remember, "serial" is not inherently packetized, while control requests are. A servo controller is definitely something that benefits from something packetized.

If you use "serial" instead, then you'd have to define another custom protocol layer and thus write a parser for that layer, which is always a pain in the ass. Also my fake serial protocol is not designed to be fast.

User avatar
zx11ninja
 
Posts: 14
Joined: Fri May 23, 2014 2:21 am

Re: USB servo via trinket

Post by zx11ninja »

Hi all.

unixnerd777, I too have felt your pain.

I read through and tried to implement the fake USB port to allow the Arduino 1.0.5 IDE to communicate with my 3V Trinket. I followed the fake USB instructions to the letter, yet I failed to get the connection to work. In trying to implement the instructions, I found out that the author's "socat PTY,link=COM8 PTY,link=COM9" was a malformed command. However, I believe I read somewhere that the author mentions he is not a UNIX/Linux expert, and I respect that. Also, the author mentions that the instructions were not tested on Linux. That is unfortunate, but I respect that as well.

If you are simply trying to program your 3V Trinket via a Linux machine, I was able to successfully do it once I worked out the bugs in my methodology on my Mac Book Pro running Mac OS X 10.7 (Lion).

To program your 3V Trinket via a Linux box, here are the steps that I followed:

1:
Download and install the 1.0.5 version of the Arduino IDE, as it already has the 8 MHz Gemma, 8 MHz Trinket, and 16 MHz Trinket built into the Tools->Board menu.

2:
Using a known good USB cable, connect your 3V Trinket to the mini-USB end of your USB cable, and connect the USB-A end of your USB cable to your Linux computer. The connecting of your 3V Trinket to your computer will not cause Linux to enumerate it as a device beneath /dev. However, the "lsusb" command will show the Trinket present on the USB bus.

3:
Launch the Arduino 1.0.5 IDE.

4:
Under Tools->Board, select Adafruit Trinket 8 MHz.

5:
Under Programmer, select USBtinyISP.

6:
Under File->Examples->Basics, select Blink.

7:
The Trinket does not have a blinking green led like the Mega 2560 does. However, you can manipulate the red led to blink. To do so, within the sketch code, change "int led = 13;" to "int led = 1;"

8:
To program the Trinket with the new sketch, press the reset button once.

9:
As soon as the red led starts blinking brightly and quickly (this indicated bootloader mode), click the Upload (right arrow) button of the IDE to compile and upload your sketch to the Trinket.

10:
If you see the "Done uploading" message at the bottom of the IDE, it means that the sketch successfully uploaded to the Trinket. The red led should start blinking such that it stays lit for one second and turns off for one second.

11:
If you can not successfully upload your sketch during bootloader mode, perhaps your sketch is large and took more time to compile than the allotted 10 seconds of bootloader mode. This means you must resolve the timing issues. To slow things down, you may try selecting "Show verbose output during" under Preferences. Initially, I selected verbose during upload. However, I realized that it was not necessary. As long as the upload starts before the ten second bootloader window ends, it seems that the sketch will continue to upload even after the ten seconds expires.


I have successfully performed the above Linux instructions on both USB3 and USB2 ports. When using USB3, I did have a timing issue situation where the sketch did not upload during bootloader mode, and the bootloader window was extended beyond ten seconds. I simply clicked the Upload button again, and the sketch finally uploaded successfully.


I hope the above helps you an anyone else that is trying to program their Trinket from a Linux machine.


Take care.

-Z

User avatar
pellico
 
Posts: 31
Joined: Thu Aug 15, 2013 6:20 pm

Re: USB servo via trinket

Post by pellico »

FWIW, I've been attempting to get a 5V trinket working on a Ubuntu 14.04 system. I had to go to Arduino 1.5.7beta because the 1.0.5 version was having issues with compiling the assembly code used in the driver(-x assember-with-cpp required but was using -assember-with-cpp). Had to load up new version of hardware addon to get Trinket 8Mz and 16Mhz and finally got the sketch compiled but with a warning of redefinitions of __SFR_OFFSET from 0 to 0x20. But did verify blink sketch could be compiled and uploaded by changing blink freq and uploading.

on the python USB side the default python-usb package would not work so had to get from git and compile and load. used this script:
#!/bin/bash
# python-usb does not have usb.core so we need it from git
pyusbdir="$(mktemp -d)"
pushd "$pyusbdir"
git clone https://github.com/walac/pyusb
cd pyusb/
git checkout 1.0.0b1
sudo python setup.py install
popd
sudo rm "$pyusbdir" -rfv

Now, running the socat command then the python TrinketFakeUsbSerialHostSW.py command results in it listening for the Trinket and then when found errors out with complaints in syslog(dmesg) that usbfs is claiming the interface while python is trying to configure it.

close but no go so far.

BTW, I'm attempting to get this fake USB serial working to see if I can get the Python API v2 working against the Trinket. This requires serial access to the Trinket.

UPDATE1: I forgot to mention that the usbdrv also wasn't compiling because it was looking for usbdrvasm16.inc but only usbdrvasm165.inc was provided. I found a copy of the 16MHz include and added that to the driver.
UPDATE2: changed rules.d to set both 0x0c9f and 0x1111 devices to usb and dialout group but I think moving from my USB3 port to a USB2 port is what helped. Now it connects the first time but on the 2nd loop(sleep0.01) I get a resource busy error attempting device.set_configuration(). Getting closer.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”