Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:10 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Arduino frustration

     Page 1 of 2    
Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 07:08am 19 Nov 2021
Copy link to clipboard 
Print this post

Just thought I would share my first Arduino project.

My "device" needed to do the following.

- Detect when a RFID card ( or tag ) was waved in front of it.
- Use Wifi to send the tag data to a URL ( a local server ).
- Get a response from the URL.
- Present that data on a LCD screen.

Initial plan was to use a Micromite as the brains, a RFID reader, LCD display and a ESP-01 WiFi module. Started buying stuff from Jaycar and ordering other bits from ebay.

The RFID card reader was from Jaycar and used SPI. Lots of how to's on the internet on how to wire them up to a Arduino and even a Micromite. None of the instructions worked, I was receiving no data from the RFID reader. I then discovered my RFID reader is slightly different to all the others and needed to be wired differently. Still no joy. Thanks to a suggestion on this forum, I ordered another module, a RDM6300 which has plain old serial data Tx and Rx at 9600. Cant go wrong with that, surely.

Next the ESP-01 modules arrived ( ordered 2 ). Apparently you just connect them up, power and serial, issued a AT command and it should reply with OK. Nope. My cro could see the AT request at the Rx pin of the module, but no reply, on any serial speed. So figured they hadn't been flashed with the firmware. Found lots of instruction on how to flash them, but guess what, none of them worked. Mr Google tells me a lot of people are having the same problem, but if you buy a USB to ESP-01 programming module, it works. So ordered one of those.

Went to Jaycar and bought a Wifi Mini ESP8266. Connected it up, issued a AT, and got a OK in return. Finally getting results.
A collogue suggested I use the ESP6288 to do everything and not have the Micromite, I just needed to learn about Arduino programming. Installed the Arduino IDE, and got into it.

Connected up a 20*4 LCD screen using a I2C interface to the ESP8266 I2C pins, and got it working thanks to a few code examples. Next tried the onboard Wifi, got that to request a URL and print the response on the LCD screen. I was getting closer.

Next was to get the RFID reader working, and I'm on the home stretch. But no matter how many instructions I looked at, it refused to work.

Today the RDM6300 RFID reader arrived. Tested it with a USB-Serial converter, and it was sending data at 9600 baud every time I waved a RFID card at it. Now to just get the ESP8266 to process the serial data.

You would think this would be easy.

The ESP8266's onboard Tx and Rx lines are connected to the on board USB-Serial circuit, and cant be used, as the Rx line is held low for some reason. So how about the other pins, there are about 8 spare. There is a library called "SoftwareSerial" which lets you assign any two digital pins as a Tx and Rx line. Installed it and tried the examples. Didn't work. After a lot of googling, yep, it doesn't work and you need to use "EspSoftwareSerial" instead. Installed that and ran the examples. Guess!

That's right, its doesn't work either, unless you disable the WiFi, as it uses the same interrupts or something. So I cant use serial on the ESP8266 unless I dont want to use the WiFi. Arghhhhh.

So back to the ESP-01. Even though its only got 8 pins, I can in theory use both the onboard serial and I2C at the same time, therefore use the WiFi, LCD and RFID reader. I just need to wait for the USB-ESP-01 module to arrive and see if I can program these ESP-01 modules.

One last note, I was checking my voltages, that was never a issue. Most of the modules are 3.3 and my USB-Serial adapter was set up that way. The RDM6300 is 5v, but I ran the serial output through a resistor divider to give 3.3v signals on the ESP8266 input pins. I also added any pull up resistors or capacitors as many of the instructions suggested.

In summary. Arduino is not easy, and most of the instructions and examples you see for these modules do NOT work.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5645
Posted: 07:36am 19 Nov 2021
Copy link to clipboard 
Print this post

I think part of the problem is with moving goalposts. Those instructions probably did work at one time - using modules from a given supplier. That supplier may not be around now, or may be a minor one compared to the sheer number of clones that are all just slightly different. The hardware may be identical, but the firmware might be cobbled together from two early versions and the version number is meaningless. There is also the problem of virtually non-existent ongoing quality control from some suppliers. The original versions were fine, but there are apparently no continual checks on production samples.

It's *really* annoying. It's also why a scope and logic analyzer are almost essential when you want to interface anything that's come from China. You also have to read the spec on the chip and halve the allowable load on all I/O pins in case it's an under-spec chip. You can pay a high price for cheap electronics.

And another little rant - I've never felt comfortable with the Arduino anyway. I simply don't like C or anything that looks like it. lol  I keep meaning to give it a fair chance and tackle a small project or two, but I always seem to find a good excuse not to do so ...

I *have* had ESP-01S modules working, in that I could send commands and get them connected to my wi-fi. I've not, so far, attempted to get them to actually use the wi-fi for anything though. In fact, my last attempt saw one connect quite happily but drop the connection after a few seconds - I could rely on it to do that at least. :(
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3422
Posted: 08:02am 19 Nov 2021
Copy link to clipboard 
Print this post

  Gizmo said  

....
A collogue suggested I use the ESP6288 to do everything and not have the Micromite, I just needed to learn about Arduino programming. Installed the Arduino IDE, and got into it.
....

In summary. Arduino is not easy, and most of the instructions and examples you see for these modules do NOT work.

Glenn


Hi Glenn, welcome to the world of system engineering. You have found 4 puzzle pieces, and a Collogue thought they would combine to a full puzzle. Well, appears they don't.

This is where you have to decide where to put the effort.

1/ put a lot of time, internet search, forum chat, to find a solution within the current HW.
2/ take some known building blocks and piece these together (i.e. a uMite, or a second arduino, or even a PICAXE).

If it is a one-off then option 2 is the best solution.
If you wanto to build a series, and make money out of it, go for option 1 (unless it is really not possible due to a HW limitation).

Good luck,

Volhout

P.S. Isn't it nice from Geoff and Peter, they did all the system engineering on te uMites for us... Makes life so much easier.
Edited 2021-11-19 18:07 by Volhout
PicomiteVGA PETSCII ROBOTS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 01:57pm 19 Nov 2021
Copy link to clipboard 
Print this post

  Gizmo said  A colleague suggested I use the ESP6288 to do everything and not have the Micromite, I just needed to learn about Arduino programming. Installed the Arduino IDE, and got into it.


And easy alternative to Arduino with ESP8266 D1 Mini is the Annex (basic) RDS system--my goto device with I need pin control and wifi.

annex google site no longer active but with plenty of info.

Current Annex forum
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 158
Posted: 02:04pm 19 Nov 2021
Copy link to clipboard 
Print this post

Switching between microcontrollers is never painless, especially when you are fundamentally working at a lower level as in C VS Basic. Apart from not being as familiar with a new chip, there's also the matters of choice of multiple libraries for interfacing and all sorts of "gotchas" lying in wait to trap the unsuspecting victim. I'm not bashing Arduino but MMBasic has issues as well.

Also, like MMBasic, the Arduino ecosystem have grown organically over time and there are differences with old libraries being written for the earlier AVR based chips rather than chips with different architectures. In some cases certain libraries will not work at all. This is similar to how MMBasic has differences in language keywords between old/newer versions.

That said:
The 8-pin common 8266 is not my first choice, I prefer Wemos D1 Mini (or clones) because there are more I/O pins available.

With the ESP8266 you have to keep in mind the power-on behavior of pins. Some pins are required to be in certain states for the device to power-up. Some pins also go low/high or output data during/after reset before your code starts (and in my experience scope this yourself to verify, do not rely on what you read online).

It's important to remember the context of the ESP8266. This was a device primarily designed to provide a serial interface to a WiFi network and is resource constrained. It just so happened to become popular and the available SDK and Arduino support helped with this. But, because of the small RAM this limits what can be done with the device easily. I have never gotten NodeMCU firmware (interpreted Lua) to work reliably because the limited ram is difficult for interpreted code vs compiled. Maintaining a WiFi connection also uses up CPU time (remember single CPU for doing WiFi and your code) and you cannot monopolize the CPU otherwise you might trigger a watchdog reset or strange behavior (put yield(); statement in loops that take a long time to see if it helps).

If you are not creating a high volume device where every cent in cost matters you can consider other Arduino modules, especially if you are interfacing via serial. The Arduino Leonardo / Micro support 2 serial ports, one via USB (so you can print to the Serial Monitor for debugging) and also the RX/TX pins which can interface to the ESP8266 or the RFID reader. You could also use AltSoftSerial lib to do software serial ports if you need more than one serial port (if you do this configure the other device for a slow baud rate like 2400 baud to help avoid dropping serial RX data). The Mega2560 is nice because it has 4 hardware serial ports. There are also ESP32 modules that might be a better fit than the ESP8266 (less resource constrained), also programmable in Arduino C.

I'd trade cost for less complexity in a one-off device, like Volhout suggested.

I have done WiFi with serial interfacing for a project a long time ago and didn't have an issue. What was the problem you were having?
Edited 2021-11-20 00:18 by flasherror
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3422
Posted: 02:57pm 19 Nov 2021
Copy link to clipboard 
Print this post

If I read Gizmo's complaint right the issue is that in the ESP8266 running WIFI there can only be non-time-critical interfaces (like I2C, SPI). These are clock driven, not time locked (UART = baudrate = time locked). Maybe due to the high priority of the WIFI stack.

This also reflects in the ANNEX RDS toolkit that support a zillion of peripherals, but no UART.
Maybe the ESP8266 does not have a free hardware UART..?? Maybe the D1 mini also not. And in the ESP stack there is nu such thing as a software UART in combination with WIFI.

That is why the uMITE could come in handy. It has several HW UARTS, but so has the arduino ATMEGA256 (the big one, not the UNO/nano. The UNO has only one). That will allow you to stay within the Arduino environment. You can re-use much of the code you have written already. Then use the ESP8266 as a base UART-WIFI adapter.

Volhout
Edited 2021-11-20 00:58 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5645
Posted: 03:16pm 19 Nov 2021
Copy link to clipboard 
Print this post

I liked Gizmo's original idea. It's a pity he has a problem with the ESP-01 as it's designed to do serial/wi-fi interfacing as it stands. Apart from a bit of initial configuration/tweaking it should "just work". With a serial RFID reader and a Micromite (although personally I'd use a PicoMite now - it's cheaper!) to link them together it should work nicely. An SPI interface to the RFID reader should be ok too. It's a case of getting the bits talking. It probably needs a logic analyzer on both the UART and the SPI to see what (if anything) is happening.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 158
Posted: 03:31pm 19 Nov 2021
Copy link to clipboard 
Print this post

  Volhout said  
This also reflects in the ANNEX RDS toolkit that support a zillion of peripherals, but no UART.
Maybe the ESP8266 does not have a free hardware UART..?? Maybe the D1 mini also not. And in the ESP stack there is nu such thing as a software UART in combination with WIFI.


The ESP8266 datasheet mentions that UARTs are implemented in hardware and since the D1 mini uses that same chip it is the same.

Because of hardware UARTs this is good for communication with other devices, as even if the CPU is busy with WiFi stuff no incoming (RX) chars will be lost.

No idea why Annex doesn't support UART, I'm not familiar with it. However the following links seem to suggest UART support?
https://sites.google.com/site/annexwifi/electroguard-lessons/chapter-6---serial
https://sites.google.com/site/annexwifi/electroguard-lessons/chapter-6---serial/project-1---gps
Edited 2021-11-20 01:35 by flasherror
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 04:28pm 19 Nov 2021
Copy link to clipboard 
Print this post

  Volhout said  Maybe the ESP8266 does not have a free hardware UART..?? Maybe the D1 mini also not. And in the ESP stack there is nu such thing as a software UART in combination with WIFI.


Even the 8-pin ESP-01 has Tx and Rx--supported by Annex.

Annex D1 Mini PCB files available here: D1 Mini PCB

If the ESP8266 isn't sufficient, here's an ESP32 D1 Mini version PCB

Flashing either D1 Mini version is simple using the provided Annex RDS flash tool.

~
Edited 2021-11-20 04:54 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 369
Posted: 10:49pm 19 Nov 2021
Copy link to clipboard 
Print this post

The original arduino (uno) was meant to be a teaching module, so the limits tend to echo through. There were/are few interrupts available. The default serial i/o uses the main interrupt, so if you use something that also requires time-critical handling it will probably also require that interrupt and port, and so interfere.
If you do not require the default serial i/o, the interrupt can be used for fast handling of events, it is quite fast as it is compiled code. Multitasking handling several different modules (with libraries written for different aims) is a bit of an ask.

Using chips with more resources might make it more applicable. There is a Windows install for the pi Pico  board, IE it runs arduino on pi Pico, I haven't tried it though.
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 311
Posted: 12:02am 20 Nov 2021
Copy link to clipboard 
Print this post

I'm a huge fan of the ESP32, but even with that I find they can do one task excellently (and maybe 2 if you are lucky), but the moment you want them to do more than one thing they start to get confused.

Luckily the answer is simple. I had a recent project where I wanted to create a WiFi Mesh and talk on I2C to a display. That worked great. Then I need to add RS-485 comms and it would run fine for a while, then the WiFi mesh would collapse. The answer was to just use 2 ESP-32's and connect them on the I2C bus. One ESP32 handles the RS485 and one handles the WiFi Mesh. Overkill? Absolutely, but at $5 a chip I'm not going to lose sleep over it.

Of course, if power draw is a concern this might not be acceptable, but mines is on mains supply.
Edited 2021-11-20 10:03 by PeteCotton
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 04:43am 20 Nov 2021
Copy link to clipboard 
Print this post

Actually making progress.

The problem I was having with the WiFi Mini 8266 board was the onboard serial was hard wired to a USB-Serial chip on the daughter board. So I cut the track and fitted a shorting plug across it. I can access that serial input by swapping a wire and unplugging the shorting plug.

I've written a test program to use all 3 devices every few seconds to see if they conflict. It requests a URL over wifi and waits for the response. Print the response on the LCD screen. See if anything is in the serial buffer, and print that on the LCD. Loop.

Its working.

Next challenge. The serial data from the RFID reader is hex code, a protocol called Weigand I think. 14 bytes. So next I need to write/find a parser to get the card serial number from the hex data.

Getting there.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1721
Posted: 06:40am 20 Nov 2021
Copy link to clipboard 
Print this post

For your application do you need to know the actual card number? As the HEX string is unique to each card, just record the HEX string(s) of the permitted card(s) then compare new input$ with the list of strings.

Scavenged from the interweb

Here is a demonstration of how to exploit a simple Wiegand device by employing an Arduino
device. This demo was adapted from an existing Arduino project written by JP Liew.
I personally tried this on my own device after purchasing a throwaway Wiegand utility interface.
Connect your Arduino device to a Wiegand RFID Reader by connecting the DATA 0 to your
second pin and the DATA 1 to your third pin (I used a HID reader for this part and it worked just
as well).
Create a folder and Git clone the source code.
cd arduino/libraries
git clone https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
Wiegand
Afterwards execute the Arduino IDE.
This particular code will execute and register the name and return the code of the Wiegand
device. Although this will not grant you access to any unauthorized locations, this quick project
gives insight into how easily accessible these Wiegand products truly are.
Try the example code below excerpted from JP Liew's original project.
#include <Wiegand.h>
WIEGAND wg;
void setup() {
Serial.begin(9600);
wg.begin();
}
void loop() {
if(wg.available())
{
Serial.print("Wiegand HEX = ");
Serial.print(wg.getCode(),HEX);
Serial.print(", DECIMAL = ");
Serial.print(wg.getCode());
Serial.print(", Type W");
Serial.println(wg.getWiegandType());
}
}

This seems to have some useful info.

https://www.hidglobal.com/sites/default/files/hid-understanding_card_data_formats-wp-en.pdf
Edited 2021-11-20 17:06 by phil99
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 08:12am 20 Nov 2021
Copy link to clipboard 
Print this post

  phil99 said  For your application do you need to know the actual card number? As the HEX string is unique to each card, just record the HEX string(s) of the permitted card(s) then compare new input$ with the list of strings.


+1  why break your back?

... but there is this  which gives a simple breakdown of the protocol (among a load of 101 stuff you are probably head 'n' shoulders above by now)
Edited 2021-11-20 18:27 by CaptainBoing
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5004
Posted: 08:18am 20 Nov 2021
Copy link to clipboard 
Print this post

Yeah do. Each of these cards or tags has the serial number printed on them, and thats what we use to look up who's card it is. I believe the serial number is coded into the hex response.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 08:40am 20 Nov 2021
Copy link to clipboard 
Print this post

ok, well it is all in that pdf above. Dunt look to tricky - beware the parity is calculated across the boundary of specific data bytes

"
The Wiegand protocol (26 bit mode) itself is made up of a leading even parity bit (for b0 - b11),
24 bits of data (from transponder data) and a trailing odd parity bit (for b12- b23). The 36 bit
mode has the same format except 34 bits are used to form the data sequence.
For example:-
Converted BCD data: 00 00 04 60 22 12 75 (14 digits)
Truncated BCD data: 04 60 22 12 75 (10 digits)
Wiegand 26 bit sequence:- E (b0 --------- b11) (b12 -------- b23) O
E ( 0 4 6 0 2 2 ) O
1 0000 0100 0110 0000 0010 0010 1
Where E is EVEN parity bit for bit 0 to 11 and O is ODD parity bit for bits 12 to 23
"
Edited 2021-11-20 18:42 by CaptainBoing
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 09:02am 20 Nov 2021
Copy link to clipboard 
Print this post

  phil99 said  
This seems to have some useful info.
https://www.hidglobal.com/sites/default/files/hid-understanding_card_data_formats-wp-en.pdf


hah! Sorry Phil, just realised I posted the same link as you did. Engage old man mode!  
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:55am 20 Nov 2021
Copy link to clipboard 
Print this post

  PeteCotton said  I'm a huge fan of the ESP32, but even with that I find they can do one task excellently (and maybe 2 if you are lucky), but the moment you want them to do more than one thing they start to get confused.

Luckily the answer is simple.



Can be even simpler. The following loop is reading 3 quadrature encoders, millions of times per second using compiled "FlexBasic"




sub encdr()

do
   Aencval = rdpin(enc_a)         ' read encoder A
   Bencval = rdpin(enc_b)         ' read encoder B
   Cencval = rdpin(enc_c)         ' read encoder C
loop

end sub



Huh? But what good is that?...it's stuck in an endless loop!

True but it's assigned to 1 of 8 CPUs in the Parallax Propeller. The 3 variables are global and therefore available to the other 7 CPUs    
Edited 2021-11-20 21:01 by Tinine
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1721
Posted: 12:14pm 20 Nov 2021
Copy link to clipboard 
Print this post

"Yeah do. Each of these cards or tags has the serial number printed on them, and that's what we use to look up who's card it is. I believe the serial number is coded into the hex response."

Add another column to the look-up table. Scan the HEX code into one and type the printed serial number in another, with the holder's name in a third.
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 12:28pm 20 Nov 2021
Copy link to clipboard 
Print this post

For anyone who values their time, these inexpensive modules can be a false economy. I would be more inclined to go with something like this.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024