The Mighty ATTiny85 and DigiSpark

Microcontrollers are lots of fun to play with as well as to build useful things.  They come in all sizes, shapes and varieties.  I am always, however, intrigued with the tiny controllers, like AdaFruit’s Trinket.  Well, the latest one I’ve started to tackle is the DigiSpark.  The DigiSpark is small and comes in several types. I am using the USB flavor. This little guy is on a very small board, about the size of a nickel, and is, itself, a USB dongle.

WP_20150928_23_59_09_Pro (2)

It features six I/O lines, plus power and ground pins.  This thing is a little bit more versatile than the original Trinket, but not much more. The USB version has the added advantage of being a USB dongle itself, meaning you can build a project that plugs into a USB port and act as an external controller. You don’t need USB, once you have programmed it, the power and ground pins can be used to power the device.

The nice thing about the DigiSpark is that you can use the Arduino IDE and SOME of the libraries to program the device.  There is a nice tutorial on setting up a newer release of the IDE and add DigiSpark support.

In a nutshell:

  1. Start the IDE (Install 1.6.x if you don’t already have it installed)
  2. Click FILE, then PREFERENCES
  3. in the Additional Boards Manager URL’s box, enter: http://digistump.com/package_digistump_index.json
  4. Click OK
  5. Click Tools, then BOARDS
  6. Select Board Manager and then Contributed
  7. In the dialog box that pops up, select DIGISTUMP AVR BOARDS
  8. Click Install
  9. Close the Board Manager
  10. You should now see the DigiSpark boards in the IDE

The thing that tripped me up was uploading a sketch.  I didn’t realize that you don’t need to have the device plugged in prior to uploading (you are told this, but it didn’t sink in.)  Once I unplugged the device, clicked upload and THEN plugged it in, it worked like a charm.

So, now I have to figure out what I want to do with this cool little device. 

But, wait…I still have not really said anything about the device, what it has on it, etc.

It is based on the ATTiny 85 and features six I/O pins:

Pin outs:

    • All pins can be used as Digital I/O

    • Pin 0 → I2C SDA, PWM (LED on Model B)
    • Pin 1 → PWM (LED on Model A)
    • Pin 2 → I2C SCK, Analog
    • Pin 3 → Analog In (also used for USB+ when USB is in use)
    • Pin 4 → PWM, Analog (also used for USB- when USB is in use)
    • Pin 5 → Analog In

The ATTiny 85 specs:

  • 8 Bit Data Bus
  • 20 MHz Max Clock Frequency ( w/ external crystal )
  • 8 kB Program Memory Size
  • 2.7 V to 5.5 V Operating Supply Voltage
  • 6 I/O Pins
  • 512 bytes of RAM

Limitations:

Two things you cannot do from the IDE: burn the bootloader and use the serial monitor. Some libraries will work, most will not.  There is no short circuit or reverse polarity protection, so be careful or you will certainly destroy the board, and, if connected via USB (which it really should not be if using external power) the computer could be damaged as well.

SAMPLE IDE OUTPUT

The IDE, as with other Arduino’s, displays the compiler and upload progress in the text area below the coding window.  Several rather bothersome messages can show, but, not to worry, it is normal. See my sample output below.

Sketch uses 668 bytes (11%) of program storage space. Maximum is 6,012 bytes.
Global variables use 9 bytes of dynamic memory.
Running Digispark Uploader…
Plug in device now… (will timeout in 60 seconds)
> Please plug in the device …
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 1.6
> Available space for user applications: 6012 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94  page size: 64
> Erase function sleep duration: 752ms
parsing: 50% complete
> Erasing the memory …
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete
>> Eep! Connection to device lost during erase! Not to worry
>> This happens on some computers – reconnecting…
>> Reconnected! Continuing upload sequence…
> Starting to upload …
writing: 70% complete
writing: 75% complete
writing: 80% complete
> Starting the user app …
running: 100% complete
>> Micronucleus done. Thank you!

Micronucleus is the name of the bootloader.  The disconnect message was a little disturbing, but not a problem.

Maybe I’ll adapt my Battlestar Galactica LCD game to this thing…

Here is a link to the Trinket posts on the blog. It is very similar to the DigiSpark.

digiStump is the maker of the device and they have other products as well. Take a gander around their site. There is a nice Wiki page and forums.

Finally, you can purchase one from Amazon for $4.88 each.  Of course, you can support digiStump by purchasing the device from them, they sell it for $8.95, a little higher than Amazon, but you will be supporting the makers and encourage further development of the product.

Using a knock-off 232 to USB converter? Better check that chip!

WP_20140705_010FTDI recently submitted a couple of drivers to Microsoft for automatic update via Microsoft’s Windows update feature.  The drivers work well, IF you are using a USB to RS232 converter that uses FTDI’s chip. If, however, you are using a ‘knock-off’ or a clone chip, these drivers will render them useless. 

The drivers reprogram the PID to all zero’s and cause the devices using the cloned chip to appear as something other than an FTDI to the drivers.  This makes them useless, even if used with older drivers or Linux.

FTDI has long been battling these cloned chips and this is the latest salvo. Previously, they just would not work with Windows 8.x if you used an 8.x driver. The 7.x drivers worked great under Windows 8.x and still do.  Though, I think I have a converter using one of the cloned chips and Windows did, in fact, update that driver. Now, however, that particular device does not work with the old driver.

There is a recovery tool, available from FTDI, that fixes the issue, but if a newer driver is used again, you will have the same problem.

Microsoft reached out to FTDI and the drivers in question have been removed from Windows Update.

 

Thanks to reader Thomas Foster for bringing this to my attention.

Bad, bad Lero…err, USB…baddest USB in the whole town

USB. We all use it. It is ubiquitous these days. Our phones use it for power and to transfer data to and from the phone to a computer. Our keyboards, mice, mobile devices, external hard disks, cameras, you name it, it probably has a USB port.  Even some of our power outlets in the wall have them.  So, why am I saying something you already know? Well, two gentlemen at SRS Labs have ‘discovered’ something that many of us probably knew, but just didn’t want to admit.

usb-drive-2What’s that, you say?

Well, unless the USB device is a simple power adapter, it contains a tiny little computer.  Yep, the two dollar USB Thumb drive is, in fact, a full fledged little computer. It has a CPU, internal memory, firmware (the OS or software that makes it all work, including the complicated USB protocol itself) and, of course, the gigs of memory that you bought it for. So, what does this mean? 

Well, for the vast majority of things, it means little.  However, there is a significant portion of USB devices-mainly the aforementioned two dollar thumb drive-that contain EEPROM instead ROM.

EEPROM is erasable programmable read only memory. It is a type of ROM that can, with the right combination of hardware and software, have its memory replaced-something standard ROM cannot do.  ROM, or READ ONLY MEMORY, is a write once memory. That is, once you have ‘burned’ or uploaded whatever you want to put in it, it cannot be changed. So, you better get it right the first time.  Which is why, I’m guessing, that some of the lower cost drives use EEPROM instead of ROM.  Perhaps the same chips are used in two or three memory sizes. It is easier to re-burn an EEPROM with different parameters than to purchase unused ROMS, go through the hassle of burning them, etc.   EEPROMS are just convenient.

So, what, exactly does this mean? So what if they used EEPROM, what does that have to do with me?

Simple: YOUR USB device COULD be hacked and its firmware changed to accomplish something more nefarious than just saving your Leonard Nimoy musical collection. 

For example, say that two dollar thumb drive was intercepted at some point before it got to the store. It’s firmware changed so that when you plug it in, it makes a copy of itself on your computer. It plants something in your operating system that allows it to copy itself back to other USB drives. Oh, it also could record your keystrokes. Or, perhaps, it could encrypt your data. Bottom line is that you don’t know what it could do.

One concern is that the device, if compromised, could actually overwrite your computer’s operating system.  Now, the chances of this happening are astronomical. I chuckled when I heard it, but…it is not out of the realm of possibilities.  So, maybe unplug the thumb drive before you shut the computer down, if you do that.

Now, before you go throw them all away, consider this:  there’s been no known exploits.  Most USB devices likely use real ROM-certainly the firmware in that Seagate you bought is in ROM. The chances of your computer actually being able to re-program other USB devices is likely slim. These embedded computers are limited in what they can do.

I, personally, am not too concerned about this, but I will think twice about grabbing that freebie drive or getting them at the Dollar General or Five Below. (Note: those are two fine stores, but some of the merchandise may not be as fine. They cannot control distribution from end to end. Just saying)

The two researchers are presenting their findings at the Black Hat conference this week. I will follow up this post with any additional information they present.

Steven Nichols has a typical story that came out this past week regarding BadUSB. Have a gander here.

Why, Apple, why? An iPad ordeal

Way back in April of 2010, about three weeks after it became available, I eagerly purchased an Apple iPad. Man, was this the device of my dreams, or what? Indeed, I had wanted a tablet for a decade, ever since I saw a really poor Fujitsu tablet with Windows 95 and ‘Pen Windows’ extensions. Even earlier, I once had an Epson ‘notebook’ which was similar to the TRS-80 Mod 100.

So, now I had this dream device.  I bought EVERY accessory for it that Apple came out with in those first few months. The keyboard dock. The video out cable. The Camera Kit. The case. Extra cables. I was so excited. I showed it to everyone I saw. After using it and downloading some useful apps, I thought this thing could replace my laptop.

After the death of my wife, I took my son on a rollercoaster tour of Maryland, Virginia and North Carolina. We hit up Six Flags America, Trimpers in Ocean City, Maryland, Kings Dominion and Busch Gardens in Virginia and Carowinds in Charlotte, NC. I had several digital cameras with me and took a lot of photos and video. At the end of each day, I would-using the Camera Kit, which was just an SD card adaptor and a USB adaptor-upload photos from the cameras to the iPad and then correctt them, catalog them and upload a few to Facebook or Picasa. For the next few years, I did this. I used the iPad as a laptop replacement.

Over time, though, it was less and less useful. As Apple brought out new models, my old iPad really began to show its age. I used it less and less and the laptop, which had showed its prowess many times, saw more and more use. My Kindle Fire picked up a lot of what I used the iPad. My Asus Windows 8 tablet sealed the iPads fate: it got relegated to kid duty.

A few days ago, I picked it up and began to peruse the photos. I realized that there were many that I did not have anywhere else. Hmmm…now I have to get them off.  Easy.

NOPE.  Apple made it nearly impossible to get your media OFF of the iPad. As the latest iOS this thing supports is iOS 5.1, I had few avenues.  iTunes was out as the computer I originally synced it with is long gone and iTunes will not allow multiple computer sync. Really.  How inconvenient is that? Windows file explorer could only ‘see’ the ‘saved photos’ and NOT all of them.  What to do?

Well, there are several applications that will bypass the one computer limit and allow true syncing. However, these applications are not free and I did not want to spend money on this as it is a one shot deal. 

To get photos into the Saved Photos folder, you must select them, one at a time and copy them over.  A real pain.  So, I figured I would have to go through this rather laborious ordeal. That is, until I remembered Goodreader.  GoodReader will allow you to import photo folders and then zip them up. It also contains a WEB SERVER. A Ha!

I had a plan.  I created a couple of folders in GoodReader. Imported the folders from Photos. Selected All. Zipped them up.  Fired up the web server. Connect from Internet Explorer and download each zip file. It took about an hour, but I got the photos I wanted.

Now, I ask you, why did Apple make this seemingly simple task an almost impossible on?

My PiTop is complete: Raspberry Pi and Motorola Atrix Lapdock together, at last

microplugsSo, I finally got the female to female micro-HDMI coupler that I needed to complete my Motorola Atrix Laptop project.  To recap, I purchased an Atrix Laptop dock (from Motorola) for my Raspberry Pi. The Raspberry Pi outputs video to either an HDMI cable (full size) or a crappy composite video connector (old-style RCA plug) and audio via headphone jack if using composite video.  Since the dock accepts HDMI and USB, it should be fairly easy to mate these two together for some kind of frankentop device.

Know what? It was easy.  Buuut…..getting the necessary connectors…well, that was quite the exercise.

Since both plugs on the dock were male, that meant I needed FEMALE couplers to plug the male cable into.  Finding these was just terrible. Seems that they are very niche products and I had to order them both, one on eBay and one on Amazon.

First, the easy one…I just ordered the Atrix cable kit. That comes with the USB cable I needed. I ordered from Amazon.

The second, though, I went through eBay and that came from China. Took nearly three weeks to ship!

At any rate, I got all of the necessary connectors, cables, wire ties, shrink tubing, etc. to finish the job.  Actually, just getting that damned micro-HDMI female coupler was the hardest part (and not burning my fingers with the soldering iron.)

NOTE: it is worth twisting the wires together and trying the cables first, before soldering. I did this to save myself any possible hassle should something not be right. However, when you solder them together, it is best NOT to twist them. Lay them in parallel and solder. Pre-tinning helps tremendously.

usbwiringSince I wanted to use the lapdock to power the Pi AND take advantage of the keyboard and mouse pad, I had to Frankenstein the USB cables too.  This is fairly easy: you want power only to the micro USB connector on the Pi, and DATA ONLY to the USB port on the Pi.  So…I had to cut the ends off of a full size male USB cable and cut the Atrix USB cable in half.  Carefully stripping away the outer tubing on each piece of cable, I then stripped the RED and BLACK wires on the female micro USB cable and the male micro-USB cable. These get some tubing before soldering. Once tubing is in place, carefully solder the wires. DON’T FORGET GROUND! Solder the ground wire as well.

Next, strip the WHITE and GREEN wires (the BLUE wire on the female side is not used here), place some tubing on each and solder. Next, pull the tubing over the expose wire, apply heat and set aside for a minute or two, the cable will be hot.  I used a large piece of shrink tubing on the outside, but it did not cover the actually spliced area, so…embarrassingly, I used electrical tape where the three cable ends meet. It is not pretty, but it does not have to be pretty, just needs to work.  I gave up my soldering days long ago, I pull the old iron out once in a while for repairs, not for looks.

Next, plug it all together and open the lid on the lapdock. If everything is ok, you will see your Pi booting on the gorgeous screen. Moto did a nice job selecting the screen, it looks great.

Now, after having used this set up for a few days, it is not all roses.  My biggest complaint: the damned trackpad. It does not take much to make the mouse move and you can find yourself typing where you didn’t want.  Also, shutting the lid will turn off and then turn on power to the Pi. Don’t know why, but it does.  USB can be problematic: typing and using a WiFi adaptor seem to cause a problem: the keyboard will slow. WiFi is also interefered with by the USB hub built into the lapdock. Sometimes, it gets unresponsive, un plugging and plugging back in the WiFi adaptor seems to fix it.

These little quirks aside, this combo is pretty cool. My PiTop works pretty well and it was cheap: less than a hundred bucks for everything. And the Pi is just cool…no matter what one does with it.