Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: [HELP] USB Device for a Tablet need parts list

  1. #1

    [HELP] USB Device for a Tablet need parts list

    Hey everyone,

    I made a Reddit post here asking if it were possible to make a USB attachment for my Surface Pro 3. Here's a mock up of what I have in mind. My SP3 just doesn't feel comfortable when drawing because of the keyboard placement when on my lap. So, I want to make HotKeys with a screen to display what each button does. Eventually I would like to have it attach to the side of my tablet, but i want to implement first before refining.

    Right now I need a parts list of things I need to make this work. I've been looking at these so far:

    • Teensy 2.0
    • I2C OLED screen
    • Push buttons (what kind)
    • Resistor (?)
    • Soldering Iron (which type?)
    • soldering wire (which kind?)
    • ESD wrist strap


    There's a Home Depot nearby, so I'm sure I can get soldering stuff there. Everything else I'll have to order through Amazon. Is this the right start? Is the screen the right kind/type for what I'm trying to do? This would be my first project ever. Thanks for any and all help provided.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,909
    The first suggestion before spending money with this would be to download and install arduino and Teensyduino https://www.pjrc.com/teensy/td_download.html, have a look at file->examples->teensy->USBkeyboard and https://www.pjrc.com/teensy/td_keyboard.html

    If you can work out what to do to those to do what you want that is a good start. Look especially for keypresses for drawing that will not work just as 'print' because they can be challenging to get right (escape key etc).

    See if you can modify the code to read enough buttons to send the shortcuts you want, and confirm it compiles without errors. Does not mean it will work but a good start before spending money.

    Next step would be to make sure your SP3 actually works with a standard keyboard plugged in, in case it gets special about hardware not OEM, Teensy will be emulating a generic USB keyboard.

    Then we get to the actual hardware. Would suggest a Teensy LC rather than a T2, since the cheap T2s you find online are counterfeit and highly unreliable. The LC will work with current firmware and much the same price as a legit T2.

    Buy at least two of everything, since you will blow things up learning. Especially in this case you will probably have a prototype on the bench and a pretty final version, and much much easier if you can keep testing on the prototype as final version comes together.

    OLED screens are generally pretty easy, starting point would be https://www.adafruit.com/product/931, even better if you spend the extra money and buy a couple from there (or somewhere else that has wiring photos and code to use). Means they will work, and you can work from their tutorial without guessing (note pin order is different with the Amazon model, and address needed to make it work is printed on the thing).

    For buttons it is really a case of experience them, electrically they will all work for this big thing is feel, size, apearance, can you mount them in your frame etc. If possible would suggest going to an electronics place and poke the buttons yourself, get a feel for what is not too stiff, has unpleasant finish etc.

    With soldering starting point is generally a breaboard https://www.adafruit.com/product/64 and jumper wires and not solder at all. If you get a Teensy pre soldered or know someone with an iron you can get your prototype going without one.

    If buying an iron you generally want a basic temperature controlled one, the sort that has an adjustable temperature knob, though for this project you MIGHT be able to get away with the uncontrolled type, increases risk of problems when you do not know what results were poor skill and what was the iron overheating everything. Solder wise thin solder for electronics (rather than jewelry or plumbing), the thick stuff sold for car electrical repair can work but again will probably lead to accelerated learning experiences as you trash parts.

    ESD strap is actually not a show stopper because microcontroller are reasonably robust as long as you do not pat cats with them or something. If you have one use it, but more important is not abusing the parts electrically or with the soldering iron.

    And for the plan as designed you will probably not need resistors, since you will be using pullups internal to your microcontroller https://learn.sparkfun.com/tutorials...-resistors/all and the OLED will probably have the ones it needs onboard.

    Edit: also have to point out that you can probably also do this project just by taking a cheap keyboard, gutting it and adding buttons just for the keys you want. More physical work to do, no software.

  3. #3
    Thank you so so much for the advice! I'll post back here with updates when the time comes. For now I'll look at the tutorials you linked, and try to find an electronic parts store near me (no Micro Centers unfortunately). Thanks again!!

  4. #4
    So I've got some materials to get me going on this project, and have some code for what I'm trying to implement.

    Here's a PasteBin of the code I'm using. I've verified that the code works just fine by shorting the pins with a paperclip before connecting to the breadboard.

    Here's an album of my connections that aren't working.

    I'm using Pins 0-5 for the buttons, but not sure how to connect to the breadboard to make it work. I have watched some videos, but this section is confusing.

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,374
    In terms of your connections, there are several things that need to be changed:

    1) You connected VIN to the power terminal -- on the Teensy, except when you are powering external devices that need 5v (or 3.7v if you are using lipo batteries), you want to connect 3.3v. On some Teensys (LC, 3.6, 4.0), if you connect 5v to a pin (which you would do with a button connect), you can burn out the Teensy. So you want to connect 3.3v (that is the third pin on the right side if the USB connector is facing up).

    2) You used the pinMode INPUT_PULLUP, but you used a connection to power with a resistor. There are two ways to read a button input:
    • Connect one side of the button to the data pin, and connect an appropriate resistor between ground and the data pin (this is called a pull-down resistor -- if the pin is not connected to power, it makes sure it is connected to ground). Connect the other side to the power. You would use pinMode (pin, INPUT) and digitalRead would return HIGH when the button is pressed, and LOW when it is released.
    • Connect one side of the button to the data pin. Connect the other side to ground. You would use pinMode (pin, INPUT_PULLUP) and digitalRead would return LOW when the button is pressed and HIGH when it is released. I always use this method because that way I don't have to add in a resistor.


    Look at Examples -> 0.2 Digital -> DigitalInputPullup for an example.

    However, once you've got this, you need to worry about debouncing and that a human button press if very long to a micro processor. If you are reading buttons, sometimes the state changes quickly multiple times before it settles down. There are various libraries (called bounce libraries) that will wait until the same signal is given for a small time period to signal a change.

    And even with bouncing, holding down the button will mean the loop will see the button being down thousands of times, and send a thousand messages via USB. So here what you need to do is only do the action if previously the button was low and it changes to high (or vice versa). You would not do anything if the button was in the same state as before.

    I prefer not to use those 4 pin buttons, because you always have to figure out what the orientation is (two of the four buttons are connected together always, while the other two are only connected if the button is pressed). I tend to prefer the buttons with a single pin on each side, because it can't be messed up. For example:


    Look in
    • Examples -> Teensy -> USB_keyboard -> Buttons; or
    • Examples -> Teensy -> USB_keyboard -> Media_Buttons
    Last edited by MichaelMeissner; 10-23-2019 at 04:50 AM.

  6. #6
    Quote Originally Posted by MichaelMeissner View Post

    2) You used the pinMode INPUT_PULLUP, but you used a connection to power with a resistor. There are two ways to read a button input:
    • Connect one side of the button to the data pin, and connect an appropriate resistor between ground and the data pin (this is called a pull-down resistor -- if the pin is not connected to power, it makes sure it is connected to ground). Connect the other side to the power. You would use pinMode (pin, INPUT) and digitalRead would return HIGH when the button is pressed, and LOW when it is released.
    • Connect one side of the button to the data pin. Connect the other side to ground. You would use pinMode (pin, INPUT_PULLUP) and digitalRead would return LOW when the button is pressed and HIGH when it is released. I always use this method because that way I don't have to add in a resistor.
    Here's a rewritten version of code I'm working on with your advice. Shortened it to one button to see if I can get everything working on one pin out. Right now this gives me no response. I'm getting confused on how to incorporate the example code. Am I supposed to use rising/fallingEdge in addition to what I had before, or replace it altogether?

    Also I really want to say thank you for everyone taking the time out to help me with this project.

  7. #7
    Alright, everyone, I've got everything finally working as intended! Here's the wiring and right over here is the code.

    If I want to solder this current setup the way it is, where should i look?

  8. #8
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,909
    There are lots of ways to make things permanent, but given you have a working breadboard layout something like these will be relatively straight forward
    https://www.adafruit.com/product/591
    Proto board or prototyping is the relevant search term, key thing is to make sure you understand how the tracks run so you don not get inadvertent shorts.

    You can also find various PCB prototyping services that will fab a half dozen board for $20 or depending on region and shipping. A more expensive but potentially easier to design option is
    https://aisler.net/partners/fritzing

    Or finally you can just solder the thing into a hairball and hope nothing breaks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •