Bar Code Scanner

Posted on
  • I am trying to connect a bar code scanner to my PICO.

    Serial2.setup(9600, {rx:A3,tx:A2,bytesize:8,parity:none,stop­bits:1,flow:none});
    Serial2.on('data', function(data) {
      console.log(data);
    });
    

    The response I am getting is gibberish though?

    þ
    æ
    æ
    æ
    æ
    f
    &
    æÌ
    f
    ææ
    ¦
    Ö
    

    I have tried various other baud rates and nothing seems to work. The code should read 0000027840200.
    Any ideas??

  • Can you describe how everything is connected? (sanity checking)

    I would agree that that should work, based on the datasheet, but that gibberish totally looks like wrong-bandwidth gibberish. But you can't really tell as much as one would like to with console.log, because the non-printing characters don't get escaped, so you can't actually see what all the characters are.

    Try doing:

    dat="";
    Serial2.on('data', function(data) {
      dat+=data;
    });
    
    

    Then scan something

    Then do:

    
    console.log(dat);
    
    dat;
    
    datcharvals=E.toUint8Array(dat);
    
    
    

    Each of those should print something, post the results - From that, you can sometimes figure out what's wrong with the UART settings (especially when you know exactly what the output is, as you do)

  • Just so you know (it shouldn't make any difference in this case though), you need to put quotes around the values of parity and flow as they're not built-in constants - like this:

    Serial2.setup(9600, {rx:A3,tx:A2,bytesize:8,parity:'none',st­opbits:1,flow:'none'});
    

    In this case it's fine because none would evaluate to undefined, and the default it none as well - but If you'd tried specifying other parity types then it wouldn't have worked.

    If you do have a storage oscilloscope handy then I'd really recommend connecting it to the serial port data pin. By triggering when you scan a barcode you should easily be able to figure out exactly what the baud rate is.

  • DrAzzy:

    Unit is powered by it's own power plug in. rs232 pins 2,3,5 and connected to espruino. (rx,tx,gnd). I have tried switching the rx and tx and then nothing will produce.

    ="ææææf&æÌfææ¦Ö\x00"
    =new Uint8Array([230, 230, 230, 230, 102, 38, 230, 204, 153, 102, 230, 230, 166, 214, 0])
    

    And I don't have an Ocilloscope but have a good excuse to get one now.

  • So I used the configuration Manager for the ms146 and everything checks out. A few observations though. On my Chromebook computer once the ms is plugged in through the PICO the computer become unusable. The mouse pad no longer works and random things happen to the screen (programs will close etc.). So I've been forced to use the windows computer which does not have the same issue but it did have to restart randomly. (not 100% sure this caused it) There is a test pad with the config manager and again everything seems to check out.

  • As far as I understand the scanner has an RS232 interface.
    Do you have any electrical level converter?
    RS232 is +/-12V signal. Such a voltage can blow up Espruino and USB.

  • Do you have any electrical level converter?

    Well spotted. If you were putting 12v straight into the Pico, that might explain why your PC behaved really strangely.

  • Check the voltage between idle RX or TX pin and ground of the barcode scanner, and see if it's actually 12v, not 5. It sounds like they make both versions from the docs you linked...?

  • Voltage is 7.54 volts between the RX and TX.

  • Please measure between tx / rx and ground on the barcode scanner, with those wires connected to nothing else. So there will be 2 measurements, tx to ground, rx to ground.

    It sounds like it's RS232 though, so you're going to need something like a MAX232 to shift the voltage down to 5v levels.

  • Siting idle the tx to ground is 8.6mV and the rx to ground is -7.53 V. The wall adapter powering the barcode scanner is a 5V @ 300mA

  • Looks like it's outputting at RS232 levels - though I'm surprised the TX is at ground, i'd expect it to be at the same level as the RX when idle...

    You need something like a MAX232 or equivilent to shift the voltage back into the range that can be safely interfaced with the Espruino.

    Hopefully nothing was permanently damaged by hooking it up directly.

  • Everything was fine with the Espruino. I built this. The voltage is now at 3.3 volts but it still causes my chromebook to freeze up. On the windows screen still cant seem to make it work properly. I might abandon this barcode scanner for now.

  • Great - glad the voltage levels are ok.

    Very strange about the freezing then. How about trying one of the latest firmwares like this? USB has had a lot of work done recently and it may fix your problems - there were a few things I needed to fix before I did a 'proper' release, but I think they're sorted now.

  • YES Got it to work. I actually some how had mixed up the capacitor and the diode...woops... and I also found that the voltage must come from the VBAT.

  • Great! Any idea what was happening before then? Were there too many volts going into the Pico?

  • Yeah I am pretty sure I was throwing it too much juice. I also received my oscilloscope the other day. It will take me a little time to figure it (oscilloscope) all out but ill do a little testing soon and fill you in.

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

Bar Code Scanner

Posted by Avatar for Cale @Cale

Actions