• Can I talk to the computer that I am plugged into over the USB connection?

    I have to make a motion sensor that can be 'noticed' by a webpage on a kiosk

    I say 'noticed' because the webpage doesn't need to know how much motion there is, just that some has been seen. I am the one writing the webpage so I can do anything I need there

    I won't have a wi-fi network, and the Ethernet jack is in use already on the kiosk computer.

    It would be so nice if I could tell that computer I am a mouse and that the mouse has moved.

  • What OS is the computer running? If it's a Mac, Linux or Android then you can get the Espruino Pico to pretend to be a USB keyboard or mouse, which makes getting input in easy: http://www.espruino.com/USB

    Otherwise, you can talk over USB Serial, but webpages (unless they're Chrome Web Apps) aren't allowed to do that.

    The other super-hacky solution is to use the headphone/mic jack and the Web Audio API to get data into the PC: http://www.espruino.com/Headphone

    Potentially you could do that without a Pico at all, but it's quite likely the Webpage could glitch and miss the 'edge' created by the motion sensor - it might be easier to use an Espruino to create a square wave on the input pin when motion was detected - then it's far less likely that it'll get missed.

  • Just to add, USB HID might still work on Windows, but it might need a 'inf' file making for it - unfortunately it's something nobody's managed to get working yet :(

    Worst case, it's entirely possible you could take a cheap USB mouse apart and then wire the motion sensor across one of the buttons on it (assuming the voltages are correct).

  • This is great !! I'll report back in a week or so as to how well it worked out !!

    Pico has become my absolute go-to computer for all hardware stuff.

    I've ditched all my Arduino's -- I tried a Tessel2, but it's actually running OpenWRT and just executes the Javascript, might as well be a Pi or something with a real OS

    Thanks!!

  • actually I'm going to be using the new websockets mqtt in parts of this project, so I could maybe run a shell-level process to listen for that data and forward it that way...

    where's the page talking over the USB serial ?

  • oh, and it's mac I develop on and linux it'll be installed on

  • Thanks! Glad you're finding it useful!

    it's mac I develop on and linux it'll be installed on

    Awesome, then it sounds like USB HID is the really easy fix.

    If you do have a process running then yes, you could use MQTT. It might be overkill though...

    For USB serial, take a look at http://www.espruino.com/Interfacing

    You might find it's easier to just use Espruino's REPL and post raw JS commands to it...

    But if not, you can use Serial1.setConsole to move the REPL out of the way so you get full access to the USB serial port with USB.write and USB.on('data', ...)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can I talk to the computer that I am plugged into over the USB connection?

Posted by Avatar for user58511 @user58511

Actions