How to connect a thermal printer to an ESP32? - printing

I want to attach my GOOJPRT Thermal Printer (I believe model QR701, communication RS232) to my ESP32 but I cannot seem to get them working.
I tried all the Adafruit Thermal Printer library examples but get the same error each and every time:
"Error compiling for board ESP32 Dev Module."
I guess the libraries are not meant for the ESP32.
I also tried the "Thermal Printer Library" by Larry Bank (which should be compatible with the ESP32 according to its github docs) but there I cannot figure out how to connect the wires of thermal printer to the ESP32 correctly.
Of course, I do not ask for a specific solution, I am just looking for someone to point me in the right direction!
This is an image of the exact thermal printer I have
Full error message from Adafruit Thermal Printer examples:
C:\Users\Thomas\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:41:27: fatal error: avr/interrupt.h: No such file or directory
compilation terminated.
Multiple libraries were found for "Adafruit_Thermal.h"
Used: C:\Users\Thomas\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library
Not used: C:\Users\Thomas\Documents\Arduino\libraries\Adafruit-Thermal-Printer-Library-master
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\Thomas\Documents\Arduino\libraries\SoftwareSerial-master
Not used: C:\Users\Thomas\Documents\Arduino\libraries\EspSoftwareSerial
exit status 1
Error compiling for board ESP32 Dev Module

You need to use the <HardwareSerial.h> library. SoftwareSerial is for Arduino boards.
"Thermal Printer Library" by Larry Bank is for GOOJPRT PT-210 and use Bluetooth. Won't work for qr-701.
Instead of using Adafruit Library, you can try with this:
ThermalPrinter
Quick start:
Import libraries:
#include "TPrinter.h"
#include <HardwareSerial.h>
Set baudrate and pins.
const int printerBaudrate = 9600; // or 19200 usually
const byte rxPin = 16; // check datasheet of your board
const byte txPin = 17; // check datasheet of your board
const byte dtrPin = 27; // optional
const byte rsePin = 4; // direction of transmission, max3485
You need to use boad with max3485(for 3V3 logic lvl) or similar, if you have printer with rs232.
Necessary in my case. I use board UART - RS485 3,3V - ARK/RJ11 - Waveshare 4777
Init
HardwareSerial mySerial(1);
Tprinter myPrinter(&mySerial, printerBaudrate);
void setup() {
micros();
mySerial.begin(printerBaudrate, SERIAL_8N1, rxPin, txPin); // must be 8N1 mode
pinMode(rsePin, OUTPUT); // optional
digitalWrite(rsePin, HIGH); // optional
// myPrinter.enableDtr(dtrPin, LOW); // optional
myPrinter.begin();
}

Related

Lua ESP8266 script expecting extra =

I am trying to test a proximity sensor with my ESP8266, however the test code I am using keeps failing.
Whenever I run the code, I get an error: motion sensor.lua:1: '=' expected near 'int'
I should also mention I am using ESPlorer v0.2.0
const int PIRSensorOutPin = 2; //PIR Sensor OUT Pin
void setup() {
Serial.begin(9600);
pinMode(PIRSensorOutPin, INPUT);
}
void loop()
{
if (digitalRead(PIRSensorOutPin) == LOW)
{
Serial.println("Person detected!"); //Print to serial monitor
}
else {;}
}
What am I doing wrong?
The Lua interpreter doesn't understand C++.
You're running NodeMCU firmware which runs Lua files. But you're trying to run Arduino C++ code. That's not going to work. To run this code you would have to add ESP8266 support to your Arduino IDE, compile your code and flash it onto the ESP.
Alternatively write your code in Lua.
https://github.com/esp8266/Arduino
https://www.nodemcu.com/index_en.html
What am I doing wrong?
Using the wrong programming language.
NodeMCU wants to run Lua code and you're giving it C code instead, which just can't work.
How do I fix it? (implied)
You can use the arduino IDE to write C++ code for ESP8266, but since you already seem to have everything set up to run Lua code, I suggest just using that instead.
The C code you provided could be rewritten into Lua using the NodeMCU api like this:
local pin = 2 -- The number of the I/O Pin
local type = "down" -- Trigger on falling edge
-- https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpiotrig
gpio.trig(pin, type, function()
print("Movement detected, proceding to exterminate!")
end)

Watchdog Timeout on SPIFFS.begin or SPIFFS.format

I'm using an ESP-12E NodeMCU board from amazon with the Arduino IDE. It's been working without any problems but now I'm trying to use SPIFFS to store data and I'm getting a Watchdog Timeout after 8 seconds when I call either SPIFFS.begin or SPIFFS.format.
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset
I've run the example CheckFlashConfig sketch and it reports a size mismatch. IDE size of 4M and real size of 1M. I'm using the Adruino IDE board definition for NodeMCU 1.0 (ESP-12E Module) with a flash setting of 4M (3M SPIFFS).
Flash real id: 001440C8
Flash real size: 1048576
Flash ide size: 4194304
Flash ide speed: 40000000
Flash ide mode: DIO
Flash Chip configuration wrong!
Here's the full code of the CheckFlashConfig sketch:
/*
ESP8266 CheckFlashConfig by Markus Sattler
This sketch tests if the EEPROM settings of the IDE match to the Hardware
*/
void setup(void) {
Serial.begin(115200);
}
void loop() {
uint32_t realSize = ESP.getFlashChipRealSize();
uint32_t ideSize = ESP.getFlashChipSize();
FlashMode_t ideMode = ESP.getFlashChipMode();
Serial.printf("Flash real id: %08X\n", ESP.getFlashChipId());
Serial.printf("Flash real size: %u\n\n", realSize);
Serial.printf("Flash ide size: %u\n", ideSize);
Serial.printf("Flash ide speed: %u\n", ESP.getFlashChipSpeed());
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
if(ideSize != realSize) {
Serial.println("Flash Chip configuration wrong!\n");
} else {
Serial.println("Flash Chip configuration ok.\n");
}
delay(500000);
}
I bought a 2nd Amica NodeMCU unit from another vendor and had no problems. I'm chalking this up to bad hardware.
This problem can also be caused by inappropriate power supply. I know from my own experience that the Arduino Uno and most USB-TTL converters cannot safely deliver enough current to the ESPs. If you're not already, consider using a dedicated power supply circuit that are connected to a USB power source.

ZBar processor and delphi

Ok so I have been trying to get bar code scanning to work in a delphi application for the last 3 weeks now. Ive been directed to this example but that example uses other librarys like imagemagika and is a console application. I am looking for a vcl forms application.
Here is some code I have written to try and see if I can get the ZBar processor to work in delphi :
// Create Processor
processor := zbar_processor_create(0);
zbar_processor_set_config(processor, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// Initialize processor
zbar_processor_init(processor, {what do I put here ?}, 1);
// Setup a callback
{I dont know what do here}
// Enable preview window
zbar_processor_set_visible(processor, 1);
zbar_processor_set_active(processor, 1);
This code is based on a example in C that I found here : https://github.com/ZBar/ZBar/blob/master/examples/processor.c
as well as the documentation over here :
http://zbar.sourceforge.net/api/zbar_8h.html#c-processor
The zbar window opens but it does not show the video feed because I parsed nil as a paramater in the initialize step. In the example they have this C code but I have no idea what it means :
const char *device = "/dev/video0";
/* initialize the Processor */
if(argc > 1)
device = argv[1];
zbar_processor_init(proc, device, 1);
If I parse '/dev/video0' instead of nil the video feed still doesn't show. So I guess my question is what do I need to parse in zbar_processor_init() function ?
I also dont know how to set up a callback function that will be called once a result is found. How would I go about doing this ?
Thanks in advance,
Kobus
argc is the number of parameters passed in the command line and argv fetches them. dev/video is linux style device. Try con:
zbar_processor_init(processor, 'con:', 1)
Con: is the console. Com1: serial port 1, Aux: auxiliary port - probably usb, Prn: the printer Lpt: the line printer.

Beaglebone Black with MIDI input (via USB) -> can't detect proper port

A few days back I wrote question regarding MIDI and ALSA, but I've since solved the problem and run into a new one.
the context in short:
I have a Beaglebone Black with debian 7.5 on it.
My host is a 32bit Ubuntu 14.10 installation.
I'm using Qt4.8.6 for arm cross-compilation.
I am trying create an application which uses a touchscreen and also reads MIDI input from a keyboard. I've used the following tutorial (http://embedded.von-kannen.net/2014/05/21/qt-4-8-6-on-beaglebone-black/) to install Qt embedded so I can crosscompile to my beaglebone (Tutorial needs some fixes, I've got a 'fixed' doc ready if anyone needs one) and the following one to compile ALSA for use on an ARM MPU: omappedia.org/wiki/ALSA_Setup
Basically after I finally got the program building and deploying onto my beaglebone black it couldn't find the port it needs to receive the MIDI signals.
I'm using a MidiMate II to connect the MIDI device I'm using to a USB port on a HUB in my Beaglebone Black.
I have the following code to check for available ports (C++):
RtMidiIn *midiin = 0;
// RtMidiIn constructor
try {
midiin = new RtMidiIn();
}
catch ( RtMidiError &error ) {
error.printMessage();
exit( EXIT_FAILURE );
}
// Check inputs.
unsigned int nPorts = midiin->getPortCount();
qDebug() << "\nThere are " << nPorts << " MIDI input sources available.\n";
std::string portName;
for ( unsigned int i=0; i<nPorts; i++ ) {
try {
portName = midiin->getPortName(i);
}
catch ( RtMidiError &error ) {
error.printMessage();
delete midiin
}
std::cout << " Input Port #" << i+1 << ": " << portName << '\n';
}
I can confirm that the MidiMate functions properly with Ubuntu. As running the application on desktop receives values just fine. I'm not certain of functionality on Debian for the BeagleBone.
The above code tells me there are no available input sources when ran on the Beaglebone, as opposed to the 2 available input sources when ran on both Ubuntu and Windows desktops.
my question:
How can I get my Beaglebone to detect the port that I need for reading the live MIDI input?
edit:
plugging the midimate into the beaglebone generates a midi1 entry int the /dev/ list.
however I don't know what and how to do with it.
the RtMidi function I use can only accept an unsigned integer as input so I can't provide the string "midi1" as an argument :(
Your distribution does not load the snd-seq and snd-seq-midi kernel modules when booting, and has no mechanism to load them on demand either.
Add them to the /etc/modules file.

how to use VxWorks etherOutputHookAdd

I'm stumped trying to get etherOutputHookAdd() to work. Its counterpart, etherInputHookAdd(), seems to work fine. The OS version in question is VxWorks 5.4 .
The hook code looks like so (the code I intend to actually run is more complicated, but this serves for an example.)
int anCounter;
STATUS etherHook(struct ifnet *pif, char *buf, int size)
{
anCounter += 1;
return FALSE;
}
I can hook up etherInputHookAdd from the vxworks shell like so
etherInputHookAdd etherHook,"fei",0
This returns 0 (STATUS OK), after which examination of the 'anCounter' variable will indicate activity as expected. However, no such luck with the output direction. I've tried both of these command lines
etherOutputHookAdd etherHook,"fei",0
etherOutputHookAdd etherHook
Both of these return OK, but the hook routine doesn't seem to be getting called at all. My best hypotheses are (1) I'm missing an initialization step, or calling it wrong, (2) the etherOutputHookAdd implementation is just a stub, (3) you just can't call it from the shell, or (4) maybe my nic driver implementation is buggy.
Any ideas that solve the central problem - how do I see what's being sent off my board - are welcome.
The following VxWorks network drivers support both the input-hook and output-hook routines:
if_cpm - Motorola MC68EN360 QUICC network interface driver
if_eex - Intel EtherExpress 16
if_ei - Intel 82596 ethernet driver
if_elc - SMC 8013WC Ethernet driver
if_elt - 3Com 3C509 Ethernet driver
if_ene - Novell/Eagle NE2000 network driver
if_fn - Fujitsu MB86960 NICE Ethernet driver
if_ln - Advanced Micro Devices Am7990 LANCE Ethernet driver
if_sm - shared memory backplane network interface driver
if_sn - National Semiconductor DP83932B SONIC Ethernet driver
if_ultra - SMC Elite Ultra Ethernet network interface driver
if_gn - generic MUX interface layer
The following drivers support only the input-hook routines:
if_nic - National Semiconductor SNIC Chip (for HKV30)
if_sl - Serial Line IP (SLIP) network interface driver
The following drivers support only the output-hook routines:
if_ulip - network interface driver for User Level IP (VxSim)
The following drivers do not support either the input-hook or output-hook routines:
if_loop - software loopback network interface driver
To those few who might stumble this way .. It was the horrible 'hypothesis 4'!
It turns out that in order for etherOutputHookAdd() to work correctly, it is incumbent on the NIC device driver writer to include a call to the function pointed to by etherOutputHookRtn. All etherOutputHookAdd() does is add your proffered packet handler to a list, so that when a NIC driver calls etherOutputHookRtn, you get a copy of what's being transmitted. Sadly, there are many drivers where for whatever reason, this was simply not done.
So in cases such as this one, there are only two courses of action.
find a patch for your driver, or patch it yourself
change tactics entirely, e.g., try using etherInputHookAdd() on the other side.
In case you migrate to a newer version (>6.x) of VxWorks , etherLib is no longer supported. Instead, one can use muxLib for a similar purpose.
Hook inbound traffic: Use muxBind with MUX_PROTO_PROMISC or MUX_PROTO_OUTPUT.
Hook outbound traffic: Use muxBind with MUX_PROTO_OUTPUT.
You should provide a callback routine in both cases.

Resources