Jump to content

Archived

This topic is now archived and is closed to further replies.

Paul Stoffregen

[Version 1] Teensyduino 0.9 Alpha Test (usb Disk)

Recommended Posts

Teensyduino 0.9-alpha4 uploaded, for Linux, Mac and Windows. Now "Disk(SD Card) + Keyboard" appears in the Tools->USB Type menu, and if you build with it, your Teensy will look for the SD card attached to the 4 SPI pins.

Here's that page where you can download it:

http://www.pjrc.com/teensy/experimental.html

Those first 15 pre-production boards should be available to order sometime this weekend. You could also wire up a SD card, just make sure to convert the power and signals to 3 volts because 5 volts will blow a SD card.

I'm sorry this is all delayed a bit... I've been testing and debugging all week. Although it was working pretty well on Linux and Mac, until yesterday there were several minor bugs with handling the SD card and reporting media status which messed things up on Windows (and makes me wonder how it ever seemed to work so well on Mac and Linux). It's looking pretty good now!

Share this post


Link to post
Share on other sites

The SD card adaptor is now available.

http://www.pjrc.com/store/sd_adaptor.html

Right now, there are only 15 pre-production boards available (yes, these were all hand soldered, but they've all been fully tested with a Micro SD card). Within a couple weeks there should be plenty of the full production boards. To use these, you'll need the latest Teensyduino 0.9-alpha4 installed.

Top Side:

sd_adaptor_top.jpg

Bottom Side:

sd_adaptor_bottom.jpg

Share this post


Link to post
Share on other sites

Whats the largest card they are compatible with?

1, 2, 4gb?

Share this post


Link to post
Share on other sites
The SD card adaptor is now available.

http://www.pjrc.com/store/sd_adaptor.html

Right now, there are only 15 pre-production boards available (yes, these were all hand soldered, but they've all been fully tested with a Micro SD card). Within a couple weeks there should be plenty of the full production boards. To use these, you'll need the latest Teensyduino 0.9-alpha4 installed.

Hi Paul,

Very happy with my teensy so far (picked up two of 'em actually). I'm definitely going to pick up one of these sd adapters down the road to tinker with. Do you sell the pins on the site as well?

Share this post


Link to post
Share on other sites

Very soon there will be pins available separately, but they're the 12 pins meant for Teensy to plug into a breadboard. You can just cut off two chunks of 5 and throw the other 2 away, and use those 5s to attach the flash card. In fact, that's what I did for the one in the photo. If you place an order for the SD adaptor before this appears on the website, just mention this message in the comment box on step #3, and I'll put one in your order.

Later, like July, maybe even August timeframe, there will be pins that are perfect for the SD adaptor. They have two black plastic parts instead of just 1, so they hold the boards apart perfectly. Unfortunately, they're a custom order part, and even though I ordered them over a month ago, it's looking like they won't be here until at least July :(

Of course, the electrons don't care which type of pins you use, though it can be a bit fiddly to get the boards lined up perfectly level to each other as you solder that first pin (notice I took the photo looking down at it, instead of a pure side view.......)

Share this post


Link to post
Share on other sites
Very soon there will be pins available separately, but they're the 12 pins meant for Teensy to plug into a breadboard. You can just cut off two chunks of 5 and throw the other 2 away, and use those 5s to attach the flash card. In fact, that's what I did for the one in the photo. If you place an order for the SD adaptor before this appears on the website, just mention this message in the comment box on step #3, and I'll put one in your order.

Awesome. I'll probably go that route.

Share this post


Link to post
Share on other sites

Woo-hoo, post-man just delivered on my day off! Off to staples to grab a fresh sd card so I can start playin around with this. (assuming I get past the soldering stage with out any major injuries). Burn cream on stand-by.

Thanks, Paul.

Share this post


Link to post
Share on other sites

Uh-oh, got myself a classic blue screen of death on my Win 7 box.

Soldered up the sd adapter. Tested the sd card separately to make sure it was kosher. Also ran some sketches on the newly modded teensy. They ran as they did before (including getting the teensy to show up using the "internal disk" setting. All good so far.

Until I tried to run with usb type set to "disk (SD card)", using the "blink" example sketch. Got myself a BSOD the first time, then a windows message telling me card should be formatted the second time (although it never showed up as a drive, like it did using the "disk internal" setting), and on the third go I got a format message followed by BSOD as soon as I canceled the format dialog box.

Time to check my solder points, and try again, I guess. :)

Share this post


Link to post
Share on other sites

OK, confirmed that its was my half-assed soldering that was the issue here. Added some extra solder and it was recognized as a drive without a hitch. My test files that I dropped on the card earlier are visible now.

On to the next problem, drive is coming up as write protected(?)

Share this post


Link to post
Share on other sites
Alpha #2 uploaded.

Most changes are bug fixes and changes in the Arduino tools menu. The installer looks the same, but got a major rewrite so it can install to any supported Arduino version. I somehow broke 0016 on Windows (and whatever java exception isn't being thrown to the console, so I can't figure out why.... windows, grrrrr) so only 0017 and 0018 will install. On Mac and Linux, 0016 to 0018 install.

http://www.pjrc.com/teensy/experimental.html

Still broken on USB Disk is using Serial.print() and having the board automatically reset, so you don't have to push the reset button. Those are up next, then I'm going to tackle SD/Micro-SD card support.

Please give the "Disk(internal) + Keyboard" option a try from the new Tools->USB Type menu! If you discover a bug, please tell me. Or even if it works fine, wouldn't hurt to post here with a "works for me".

Hi! Thanks for the post about the arduino .9 version. Can you explain to me what is Serial.print()? What is it used for? Thank you!

Bits1

Share this post


Link to post
Share on other sites
Can you explain to me what is Serial.print()? What is it used for? Thank you!

Usually Serial.print() is used to print info about what your program is doing, much like you might put a bunch of printf() lines inside a C or C++ command-line program. Usually you'd use the Arduino Serial Monitor, which is the right-most button on the toolbar inside the Arduino IDE, to view whatever is sent by Serial.print().

On a real Arduino board, Serial.print() sends bytes via the UART, which go to a USB-Serial converter chip. On Teensy, when you select USB Serial (with Teensyduino version 0.8 from one of the entries in the Tools->Boards menu, with version 0.9 from the Tools->USB Type menu), Teensy then implements a USB Serial device type and Serial.print() works pretty much the same as on Arduino, except at native USB speed.

Of course, unlike Arduino boards, Teensy can implement non-serial device types, and in particular HID keyboard is what pretty much everyone here is interested in. When you select any of those non-serial types, there is actually an additional "vendor specific" HID interface implemented in parallel with the HID keyboard, and Serial.print() sends data to that interface. On the PC, Teensyduino runs a special "teensy_gateway" process which listens for that custom interface and provides the data to the Arduino Serial Monitor.

So even when Teensy isn't implementing a serial device, you can still put Serial.print() into your code and a separate communication channel is emulated so it still "just works" with the Arduino Serial Monitor pretty much exactly you'd expect.

Share this post


Link to post
Share on other sites
Usually Serial.print() is used to print info about what your program is doing, much like you might put a bunch of printf() lines inside a C or C++ command-line program. Usually you'd use the Arduino Serial Monitor, which is the right-most button on the toolbar inside the Arduino IDE, to view whatever is sent by Serial.print().

On a real Arduino board, Serial.print() sends bytes via the UART, which go to a USB-Serial converter chip. On Teensy, when you select USB Serial (with Teensyduino version 0.8 from one of the entries in the Tools->Boards menu, with version 0.9 from the Tools->USB Type menu), Teensy then implements a USB Serial device type and Serial.print() works pretty much the same as on Arduino, except at native USB speed.

Of course, unlike Arduino boards, Teensy can implement non-serial device types, and in particular HID keyboard is what pretty much everyone here is interested in. When you select any of those non-serial types, there is actually an additional "vendor specific" HID interface implemented in parallel with the HID keyboard, and Serial.print() sends data to that interface. On the PC, Teensyduino runs a special "teensy_gateway" process which listens for that custom interface and provides the data to the Arduino Serial Monitor.

So even when Teensy isn't implementing a serial device, you can still put Serial.print() into your code and a separate communication channel is emulated so it still "just works" with the Arduino Serial Monitor pretty much exactly you'd expect.

Wow, thank you for your perfect answer. It makes sense now. I'm still new to all this so I wasn't sure what it does. I was hoping that Serial.read() could some how read characters on the Terminal or communicate with it.

I am currently trying to think of a way for the Teensy to read or have some sort of way to recognize its currently location on the Terminal. Like, if you stored a document somewhere and you want to locate it quickly using a Teensy, is there some way for the Teensy to determine where it is on the terminal, use "find" to locate the directory of that document and then go to that directory? I am hoping there is some way to program Teensy to search and notify me if it could find this certain document or not. Thank you very much for replying to my post and helping me out.

Bits1

Share this post


Link to post
Share on other sites
I was hoping that Serial.read() could some how read characters on the Terminal or communicate with it.

Yes, you can.

If you're using HID keyboard, then Serial is mapped to a custom HID interface. To send data to it, you'll need to write code. On Windows, you would send using WriteFile()... but opening the handle to the device involves jumping through a bunch of WIN32 hoops. You use HidD_GetHidGuid and SetupDiGetClassDevs to get a list of all HID devices, and SetupDiEnumDeviceInterfaces and SetupDiGetInterfaceDeviceDetail to inspect each one. You can look at the vendor and product ID, or you can just open the device with CreateFile, and then use HidD_GetAttributes, HidD_GetPreparsedData and HidP_GetCaps to inspect the usage page and usage numbers. Since Windows will generally let you play havoc with all non-keyboard HID devices, it's a good idea to check all 4 numbers before you go blasting out packets with WriteFile (which will give you an error if your write isn't exactly the correct packet size). Then again, if the vid & pic check out, maybe that's good enough... but you still have to use those ugly setupapi functions to get the device path name which CreateFile needs to open a handle to the device.

You can look at the Raw HID and Hid Listen programs for some example code. It's ugly WIN32 programming, but only several dozen lines which isn't too bad as WIN32 goes!

Also, if you write code with the setupapi using Microsoft's tools, you might need to get their DDK for the missing headers and stuff. I personally do all my Windows programming using MinGW as a cross compiler running on Linux. All my examples will compile "out of the box" on Ubuntu with the mingw packages installed. How to build Windows executables actually in Windows is something I can't help you with!

The other very easy, but very limited path, is you can control the 3 keyboard LEDs. Irongeek posted an example of how to read them from your program. Maybe you could use Morse code?

Of course, if you're using the SD card, you could write to it. But reading it from the Teensy involves using a library like SDfat... and if you try accessing the card while the USB is active and the operating system believes it has exclusive access, well, it's possible to get thing horribly confused.

Share this post


Link to post
Share on other sites
Yes, you can.

If you're using HID keyboard, then Serial is mapped to a custom HID interface. To send data to it, you'll need to write code. On Windows, you would send using WriteFile()... but opening the handle to the device involves jumping through a bunch of WIN32 hoops. You use HidD_GetHidGuid and SetupDiGetClassDevs to get a list of all HID devices, and SetupDiEnumDeviceInterfaces and SetupDiGetInterfaceDeviceDetail to inspect each one. You can look at the vendor and product ID, or you can just open the device with CreateFile, and then use HidD_GetAttributes, HidD_GetPreparsedData and HidP_GetCaps to inspect the usage page and usage numbers. Since Windows will generally let you play havoc with all non-keyboard HID devices, it's a good idea to check all 4 numbers before you go blasting out packets with WriteFile (which will give you an error if your write isn't exactly the correct packet size). Then again, if the vid & pic check out, maybe that's good enough... but you still have to use those ugly setupapi functions to get the device path name which CreateFile needs to open a handle to the device.

You can look at the Raw HID and Hid Listen programs for some example code. It's ugly WIN32 programming, but only several dozen lines which isn't too bad as WIN32 goes!

Also, if you write code with the setupapi using Microsoft's tools, you might need to get their DDK for the missing headers and stuff. I personally do all my Windows programming using MinGW as a cross compiler running on Linux. All my examples will compile "out of the box" on Ubuntu with the mingw packages installed. How to build Windows executables actually in Windows is something I can't help you with!

The other very easy, but very limited path, is you can control the 3 keyboard LEDs. Irongeek posted an example of how to read them from your program. Maybe you could use Morse code?

Of course, if you're using the SD card, you could write to it. But reading it from the Teensy involves using a library like SDfat... and if you try accessing the card while the USB is active and the operating system believes it has exclusive access, well, it's possible to get thing horribly confused.

Thank you for letting me know that reading from the Terminal window is possible. I will check out the commands that you have mentioned. Is this process the same with Mac and Linux? I'm currently working with a mac machine right now and then I will move onto working with Windows and Linux machines soon. I am very interested in working with SD cards and storing data onto it. I saw your posts on SD card libraries and once my sd card comes in from the mail, i will definitely make full use of it. :) Also, I saw some posts about changing Vendor ID and Product ID and the comments states go to arduino-xxx/hardware..../usb_private.h ...where exactly do I find this file? I have looked all over my mac and tried to find it on www.pjrc.org and I have no idea where...

Is it because I am coding with Arduino language and using the Arduino IDE? I saw examples on USB keyboard with these settings but coded in C. Do you prefer using C than Arduino? Looking at the complexity level, Arduino language seems easier to understand.

PS

Your comments are very helpful to me. Thank you very much.

Bits1

Share this post


Link to post
Share on other sites
Is this process the same with Mac and Linux?

Each has its own API. My examples are coded for all 3. The best way to answer your questions would be the review the actual code.

Also, I saw some posts about changing Vendor ID and Product ID and the comments states go to arduino-xxx/hardware..../usb_private.h ...where exactly do I find this file?

It's inside Arduino.app, which MacOS presents as a single file. If you right click (or option click), there's an option to show bundle contents. Then you can find the file inside. Or if you use the Mac Terminal program and navigate the traditional unix command-line way, all files are easily viewable.

I have looked all over my mac and tried to find it on www.pjrc.org and I have no idea where...

It's embedded within the Teensyduino installer. Those files aren't provided separately, because it's a real pain to manually install them all in the right places, especially the java bytecodes. The exact procedure changes with each new version of Arduino, so an automated installer is really for the best. In fact, before version 0.9, I wrote separate installers for each Arduino version. Version 0.9 unifies them into a single installer than can install into multiple versions of Arduino.

The goal is to make everything as easy as possible. Apple goes one step farther by making the Finder and default file/dir dialogs present a simplified view of the filesystem. That's nice, until you want to actually look at files within application bundles. You can access that stuff, but you have to do something special to get inside the bundle contents if you're using the Finder.

Share this post


Link to post
Share on other sites

Hi Paul,

I followed your advices and everything is going well so far. I understand the Serial.print() command and I found out where the usb_private.h is located. I used the Vendor ID and Product ID that Psyduck has. For those who wants to know, its

Vendor ID = 0x05ac and Product ID = 0x0220

this should work as a mac keyboard and dell keyboard...

I have been working with the Teensy++ and the DIP switches so that I can have different commands ready based on the states of the dip switches. I have also soldered the Teensy 2.0 with the SD card adapter so now I'm just waiting for the SD cards to come in soon. :) My next step is working on getting the Teensy to store data... :) I'll keep you updated on what I'm doing. Thank you again for your help.

Bits1

post-19954-1278104441_thumb.jpg

post-19954-1278100951_thumb.jpg

Share this post


Link to post
Share on other sites

Hi everyone,

In the new Teensyduino 0.9, there is an option of making the teensy with the SD card into a serial port. I have done some research that tells me I can have the teensy request the computer to search for a document and listens for the computer to respond whether it finds the document or not. If it did, then the teensy can have the computer transfer the documents in bits over to the teensy, which will create the file with that same name and dump all the data into it. Once its finish, the teensy can blink the light to notify the user. I can see that this is possible, however, I have not seen any EXAMPLES or any projects that has something to do with file transfer from computer to Teensy and serial ports with the Teensy. If I were to have teensy communicate with the computer to send files to the serial port (teensy in disguise) , I suppose I'm doing this on the user's behalf? and so, I worry about permissions.

Do root users only have the rights to read and write files?

What about the regular users who do NOT have administration rights?

Also, if I have the Teensy as a Serial Port, I cannot type any commands onto the Terminal.

How would you be able to request for certain documents from the computer? I guess this would mean I will be coding in C and have Teensy communicate with the PC somehow...

I have written a code that have Teensy as a Keyboard + SD Card. This code has the Keyboard calling the terminal to search for a document and then taking the output of the terminal, and move this file to the SD card that is mounted on the computer. The problem with this is that I do not know when the search is finish and whether the file is found or not.

Even if the file is found and is sent to the SD card, is there any way for the Teensy to check internally if it has this specific document?

Thank you for all your help.

Sincerely,

Bits1


void setup(){
  Serial.begin(9600);
  Serial.println("BEGIN");
  ComboKeys(MODIFIERKEY_GUI, KEY_SPACE);
  delay(100);
  //Opens the terminal
  Keyboard.print("Terminal");
  sendKey(KEY_ENTER);
  //sending out command to find this text file
    // find ~ -name "testout.txt" | pbcopy
  delay(1500);
  Keyboard.print("find ");

  ComboKeys(MODIFIERKEY_SHIFT,KEY_TILDE);
  sendKey(KEY_SPACE);

  ComboKeys(0,KEY_MINUS);
  Keyboard.print("name ");
  ComboKeys(0, KEY_QUOTE);
  Keyboard.print("testout.txt");
  ComboKeys(0, KEY_QUOTE);

  ComboKeys(MODIFIERKEY_SHIFT, KEY_BACKSLASH);
  release();
  Keyboard.print(" pbcopy");
  delay(100);
  sendKey(KEY_ENTER);
  delay(2000);
  //pasting the output of the terminal onto the textedit
  //then grabs the directory address
  Keyboard.print("open -a textedit.app");
  sendKey(KEY_ENTER);
  delay(1500);

  ComboKeys(MODIFIERKEY_GUI,KEY_V);
  ComboKeys(MODIFIERKEY_GUI, KEY_UP);
  Keyboard.set_modifier(MODIFIERKEY_GUI|MODIFIERKEY_SHIFT);
  Keyboard.send_now();
  sendKey(KEY_RIGHT);
  //copies the directory 
  delay(1000);
  ComboKeys(MODIFIERKEY_GUI, KEY_C);
  ComboKeys(MODIFIERKEY_GUI,KEY_SPACE);
  delay(100);
  //opens the terminal
  Keyboard.print("terminal");
  sendKey(KEY_ENTER);

  delay(1000);
  //moves this file to the SD card
  //mv /home/testout.txt /Volumes/"NO NAME"
  Keyboard.print("mv ");
  ComboKeys(MODIFIERKEY_GUI,KEY_V);
  Keyboard.print(" /Volumes/");
  ComboKeys(0,KEY_QUOTE);
  Keyboard.print("NO NAME");
  ComboKeys(0,KEY_QUOTE);
  sendKey(KEY_ENTER);
  Serial.println("done");
  delay(1000);



}
void loop(){}

void ComboKeys(int mod, int key)
{
Keyboard.set_modifier(mod);
Keyboard.send_now();
Keyboard.set_key1(key);
Keyboard.send_now();
release();
}
void sendKey(int key)
{
  Keyboard.set_key1(key);
  Keyboard.send_now();
  release();
}
void release()
{
  Keyboard.set_modifier(0);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.send_now();
}

Share this post


Link to post
Share on other sites

I just read from other posts about Teensy being a serial port...

This is Paul's comment a few months ago...

http://www.hak5.org/forums/index.php?showt...mp;#entry162691

When using USB Serial, which is the only way you can use normal Arduino boards, these can be used to build code which communicate with PC-based code. There's lots of code out there which communicates via serial ports, because for many years (since the 1980's even), using serial communication has been the main way to communicate with microcontrollers.

So now I'm sure that it is possible to have microprocessors communicate back and forth with the PC or Mac. This would mean I have to post some type of interface between the teensy and the computer... Hm, Answers are everywhere, I guess I have to look harder. :)

Bits1

Share this post


Link to post
Share on other sites

Hi, hopefully this topic isnt totally dead.

I have been working with the teensy for a while but have only recently had the need to work with an SD card on it. I am curious whether any system for controlling whether the teensy can read/write vs. whether the computer can read/write. Im working on an adrioid app that needs to use an SD card for logging activity and both the teensy and the computer need to have access to the card (not at the same time, but within seconds possibly). What might be the best approach to take with this?

Thanks,

Cromer

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...