fibane
February 18, 2022, 3:13pm
1
Hello,
I am trying to read the output of the GM67 barcode reader using uart bus.
I have a NodeMCU ESP8266 , which already reads the value of 2 pins for 2 binary sensors.
I’m trying to, at least debug the uart bus, however there is nothing in the logs. The config looks like this:
uart:
tx_pin: D1
rx_pin: D2
id: uart_bus
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
logger:
baud_rate: 0
level: VERY_VERBOSE
hardware_uart: UART1
I tried adding this: Custom UART Text Sensor — ESPHome but with no luck, still nothing in the logs (VERY_VERBOSE level).
I tried switching pins to TX and RX, manually telling the logger to use UART1, but I still have nothing on the logs.
Am I missing something obvious? (yes, the GM67 Bar Code has been setup to use the TTL 232 Interface… this sets: Serial port related configuration: Baud rate:9600, Data bit:8, Verification: No, Stop bit:1)
Thank you
EDIT: start logs with logger on UART1 and uart pins TX and RX:
[15:32:07][V][wifi:359]: Priority: 0.0
[15:32:07][C][wifi:361]: Channel: 6
[15:32:07][C][wifi:362]: Subnet: 255.255.255.0
[15:32:07][C][wifi:363]: Gateway: 192.168.1.254
[15:32:07][C][wifi:364]: DNS1: 0.0.0.0
[15:32:07][C][wifi:365]: DNS2: 0.0.0.0
[15:32:07][C][logger:233]: Logger:
[15:32:07][C][logger:234]: Level: VERY_VERBOSE
[15:32:07][C][logger:235]: Log Baud Rate: 0
[15:32:07][C][logger:236]: Hardware UART: UART1
[15:32:07][C][uart.arduino_esp8266:100]: UART Bus:
[15:32:07][C][uart.arduino_esp8266:101]: TX Pin: GPIO1
[15:32:07][C][uart.arduino_esp8266:102]: RX Pin: GPIO3
[15:32:07][C][uart.arduino_esp8266:104]: RX Buffer Size: 256
[15:32:07][C][uart.arduino_esp8266:106]: Baud Rate: 9600 baud
[15:32:07][C][uart.arduino_esp8266:107]: Data Bits: 8
[15:32:07][C][uart.arduino_esp8266:108]: Parity: NONE
[15:32:07][C][uart.arduino_esp8266:109]: Stop bits: 1
[15:32:07][C][uart.arduino_esp8266:111]: Using hardware serial interface.
[15:32:07][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Ajouter'
[15:32:07][C][gpio.binary_sensor:016]: Pin: GPIO0
[15:32:07][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Consommer'
[15:32:07][C][gpio.binary_sensor:016]: Pin: GPIO2
[15:32:07][C][ota:082]: Over-The-Air Updates:
[15:32:07][C][ota:083]: Address: 192.168.1.154:8266
[15:32:07][C][ota:086]: Using Password.
[15:32:07][C][api:134]: API Server:
[15:32:07][C][api:135]: Address: 192.168.1.154:6053
[15:32:07][C][api:139]: Using noise encryption: NO
[15:32:07][C][mdns:084]: mDNS:
[15:32:07][C][mdns:085]: Hostname: barcode
[15:32:07][V][mdns:086]: Services:
[15:32:07][V][mdns:088]: - _esphomelib, _tcp, 6053
[15:32:07][V][mdns:090]: TXT: version = 2022.1.2
[15:32:07][V][mdns:090]: TXT: mac = 40915145fd19
[15:32:07][V][mdns:090]: TXT: platform = ESP8266
[15:32:07][V][mdns:090]: TXT: board = nodemcuv2
chemelli
(Simone Chemelli)
May 22, 2022, 9:21am
2
My working config:
external_components:
- source:
type: git
url: https://github.com/ssieb/custom_components/
components: [ serial ]
text_sensor:
- platform: serial
name: ${description} Bar Code
uart:
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
tx_pin: GPIO17
rx_pin: GPIO16
Simone
1 Like
Lakefire
(Lakefire)
August 29, 2022, 5:44pm
3
I tried using your working config for my bar code scanner. The scanner is a different model, but I don’t think that is an issue as I can see the bar codes I scan show up in the logs. What I am not seeing is the scanned code in home assistant. The text sensor just stays at unknown all the time in Home Assistant. It seems like I am close to having it working I just don’t know esphome well enough to figure out what to adjust. I tried changing the delimiter in the uart section to \r as that shows up in the logs, but it didn’t help.
My log shows:
[11:37:10][D][uart_debug:158]: <<< "850020433223\r"
Which is the correct bar code I am testing with. Any Ideas how to make the text sensor update?
Hi @Lakefire ,
did you have any success and can share your solution with us?
Thanks in advance!
Aaron
goedh452
(Bouke)
January 6, 2024, 11:37am
5
@Lakefire @boardnick0815
Not sure it this is still relevant to you, but I had the same problem: values weren’t sent to Home Assistant. I created the lambda code myself. So no need for the external component. This is my working code:
Edit: added a character count to avoid misscans. Bar code is 13 characters, but 14 are read from the uart including the r.
uart:
id: uart_bus
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
std::string str(bytes.begin(), bytes.end());
int nuberCount=strlen(str.c_str());
if (nuberCount==14) { id(barcode).publish_state(str.c_str()); }
text_sensor:
- platform: template
id: barcode
name: Barcode
hey, is there any chance you can share your full yaml? I am struggling getting my gm67 to work. Thanks!
I had a similar struggle to get it working, but I’m using a GM60 barcode scanner module. I had to modify the lambda slightly, to remove the length checking and then I started to get barcodes read into the logs and published to a text sensor.
I’m using an esp32 d1 mini and hardware UART1 for the connection to the GM60.
I was originally trying to use a guide i found that is in German, but it appears it is for an older version of esphome and I currently don’t have the knowledge to update it
SmartHome Yourself - Barcode Scanner for ESPHome
substitutions:
name: barcode-scanner
# UART Pins for the Barcode Scanner
uart_tx_pin: GPIO17 #RX side on gm60
uart_rx_pin: GPIO16 #TX side on gm60
esp32:
board: wemos_d1_mini32
esphome:
name: ${name}
name_add_mac_suffix: false
api:
encryption:
key: ........
ota:
platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
uart:
tx_pin: ${uart_tx_pin}
rx_pin: ${uart_rx_pin}
id: uart_bus
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
std::string str(bytes.begin(), bytes.end());
id(barcode).publish_state(str.c_str());
text_sensor:
- platform: template
id: barcode
name: Barcode
web_server:
logger:
1 Like
yep, very similar to what I ended up doing:
esphome:
name: barcodescanner
friendly_name: barcodescanner
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: VERBOSE
baud_rate: 0
hardware_uart: UART1
# Enable Home Assistant API
api:
encryption:
key: XYZ
ota:
- platform: esphome
password: ABC
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Barcodescanner Fallback Hotspot"
password: DEF
captive_portal:
uart:
id: uart_bus
tx_pin: GPIO3
rx_pin: GPIO1
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
std::string str(bytes.begin(), bytes.end());
int numberCount=strlen(str.c_str());
if (numberCount>=13 && numberCount <=14) { id(barcode).publish_state(str.c_str()); }
text_sensor:
- platform: template
id: barcode
name: Barcode
on_value:
then:
- homeassistant.event:
event: esphome.barcodescanner_barcode_scanned
data:
barcode: !lambda "return id(barcode).state;"