Friday, June 12, 2020

String inputs Over Serial on ESP8266

Current issue: I'm trying to be able to enter my SSID and password over serial (so I can avoid committing that info to Git). If I hardcode the SSID and password, say mySSID and myPassword as a string object, I can connect. But if I try to type it over serial, it doesn't work. The ESP8266 uses both NL and CR for serial communication, so my current hypothesis is that it's probably an issue with that.

This happened the same whether I use Serial.readString() or Serial.readStringUntil('\n'). I could immediately tell that Serial.readString() didn't work because there was a visible newline.

Thinking there might be a character I missed (though it wasn't '\r' either), I added the following code to get the exact string:


When I enter mySSID as Serial.readString(); I get the following hex back:
6D7953534944DA0EFEF80FEEFEFFE
Which after converting to ASCII with this website, returns
mySSIDÚ þø îþÿ

If I enter mySSID as Serial.readStringUntil('\n'); I get the following hex back:
6D7953534944D0FEEFEF80FEEFEFFE
And convert to ASCII returning
mySSIDÐþïï€þïïþ

Two things I notice. First off, readString returns an odd number of nibbles. readStringUntil returns an even number of nibbles, so I have complete bytes. This certainly seems odd, but I couldn't tell you the significance.

Even more substantially (I think), there is a 0xD right after mySSID with both read methods. If there was a 0x0 between mySSID and 0xD, I would get a \n character and boom! Problem solved. So seems like maybe it's somehow getting dropped somewhere? I'll have to further investigate.

Update 2020-06-13

I guess I actually hadn't used Serial.readStringUntil('\r'). It's possible I had done something silly like specifying only 'r'.

At this point, I could connect by typing in my SSID and hardcoding the password. But because of... something it was bypassing the prompt for password. I think because it was picking up an extra garbage \n and \r from my input. So now to flush the input. Serial.flush() seems good!

Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)
 
Oh... Ok. This is fine.
 
First I tried
while (Serial.available()) {Serial.read();}

But no dice. Finally I figured out I guess it's not enough to read, you have to do something with that read data. Leading me to the code below.

String serialTrash;
do
{
    serialTrash = Serial.read();
} while (Serial.available() > 0);

Success!

References

  1. Topic: converting string to hex (the non-rude, actually helpful posts)

Tuesday, May 19, 2020

Adventures in ESP8266

You know, I have yet to encounter an electronics troubleshooting issue of which recounting doesn't feel like telling a gaff on myself.

First off, I'd just like acknowledge esp8266.com and esp8266.net as being invaluable information hubs!

If you want the solution and not the story, see this post.

Background

In 2015, shortly after the ESP8266 first came out, I used an ESP-01 module for one of my college classes. I don't remember much about the experience, but I'm pretty sure I managed to get it up and running in less than a three-hour class. Well, that and that part of the process was me casually mentioning to the lab supervisor that I unplugged one of the computers to plug into a wireless router and him saying "yeah... I'm not sure you're supposed to tell me that..."

Cut to 2017, and I finally decide it's time to dig back into ESPland with a new idea for a project. The two primary factors are 1) size and 2) I2C capability. The ESP-01 doesn't have ready-to-go I2C pins available, so I do some searching on compact ESP modules. Hey, turns out that the ESP-03 not only has the I2C pins broken out, but it's also smaller than the ESP-01! I order all my parts, start breadboarding, get sidetracked with some other project, and stow it away for playing with on some later date.

It's May of 2020, I'm quarantined at home, and I'm determined to get this thing working. So I start out with the "hello world" of the electronics world: a simple blinking light (with a bonus "Hello, World!" over serial).

Immediately I can't even load a program onto it, and remember why I packed this away three years ago.

I realize everything's out of date. So I update and still... Nothing. Let the real troubleshooting begin.

Equipment

Hardware


Software

For programming and flashing, I used the Arduino IDE. The folks at esp8266.com did a really nice job getting this bit to be about as easy as you could ask. Just add the following link to Additional Board Manager URLs, install 8266 via Board Manager, and you're good to go.
http://arduino.esp8266.com/stable/package_esp8266com_index.json

So I hook everything up, press the appropriate buttons in the appropriate order, and...

 Troubleshooting


esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

This is a phrase that will haunt me for a while.

DaedalusRising's board has the correct pullup and pulldown resistors to solve a lot of the obvious troubleshooting issues which made things handy setup-wise, but it's a little disappointing because that means this likely isn't going to be a 10 minute "oh, duh" fix.

First question: Does my FTDI adapter still work? Did I break it at some point? A simple loopback test with typing into PuTTY shows that it does indeed work.

AT Commands

After some more research, I learn about AT Commands, a set of commands to control a device over serial. Alright, let's see what we can do here.

>at
OK
Well that's good news! Next step:
>at+rst
Error
Well shoot. That's an issue. It's there, but it won't reset. Why not? Commence Googling and DuckDuckGoing that both end up fruitless.

After some further wild goose chasing, I try once more:
>AT
OK
 
>AT+RST
[Expected stuff here]

Success! Turns out that everything other than the basic "AT" is case-sensitive. Live and learn, I suppose.

ESPtool Research

So we know that our serial line works, and we know that our device seems to be working. Arduino uses esptool to communicate with the ESP8266, so next let's see if that's working as intended:

>esptool.py.exe -p COM4 -b 115200 chip_id
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

Nothing. Drat.


To get even more basic, I perform a test of just pySerial. After some trial and error, I again use a loopback with some Python code to see if I can get esptool to work.

>py loopback.py
COM4
b'hello'

Well... That's something I guess. I know that pySerial works.

Actually, this is helpful. I pretty much have it narrowed down to esptool at this point. Time to head back to Google (you know it's bad when you've reached the second page).

The Solution

With my newfound knowledge and more finely-tuned search terms, I read countless more forum posts and GitHub issues, until I run across this thread with these fateful comments:

GPIO0 is Linked to the ground

I think everyone on the planet knows about Gpio0 at this stage !

Pretty much. The breakout does has that handy Program pushbutton after all.

Yeah, but I had the same problem and it turns out that after connecting GPIO0 to ground you must restart the ESP. I mean just unplug it from the power and plug it again.

Wait... What? So I quickly try it.

WONDER OF WONDERS.

IT WORKS.

HALLELUJAH.

 Further Exploration

But why is this? Why doesn't the reset pin do the same thing? Is it a bad solder joint? No, I can probe the ESP-03 reset pin and it goes to GND when I press RST. So what's the deal?

I guess it would be too simple for the ESP-03 schematics to be readily available. At best, I can find this picture at esp8266.com:

But going through Google Images, I come across this picture:


Wait, why is that circled? I follow the link to nathan.chantrell.net and it zooms in.


Why they couldn't have broken out RST to that N/C pin is beyond me, but they didn't ask me. Maybe that's why the ESP-03 has been discontinued.

After all this, I go back to the ESP-03 page on esp8266.com

GPIO16 ... can also be connected to ESP EXT_RSTB (reset) pin by closing jumper near pin 8 ...

Conclusion

When in doubt, RTFM.

Like I said: I have yet to encounter an electronics troubleshooting issue of which recounting doesn't feel like telling a gaff on myself.

Solution to esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

I ran into this problem while messing with an ESP-03.

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

(If you want to read my whole troubleshooting adventure, see this post.)

Arduino version 1.8.12, additional board manager from this URL, esp8266 board package version 2.7.1. AT Commands respond appropriately, so I know UART is working.

Turns out out that GPIO16 on ESP-03 is by default not connected to RST. So the oft-parroted sequence of GPIO0 low, GPIO16 low then high, GPIO0 high didn't work.

Solution!

The brute-force solution for any ESP module is
  1. Remove power
  2. GPIO0 low
  3. Provide power
  4. GPIO0 high
Another solution for ESP-03 is to bridge the jumper near VCC and GPIO14. This connects GPIO16 to RST, allowing external hard reset.
Picture courtesy of nathan.chantrell.net

Why they couldn't have broken out RST to that N/C pin is beyond me, but they didn't ask me. Maybe that's why the ESP-03 has been discontinued.

Wednesday, July 3, 2019

Different Pin Numbers Depending on Footprint

My latest question:

Hi there!

When creating a schematic symbol, is it possible to have numbers in the Designator spot be generated from the footprint rather than the designator number?

For example, in the attached picture from the datasheet of an MCP23017, in the SOIC version GPB0 is pin 1. However in the QFN version, GPB0 is pin 25.

I want the same component and symbol, but to show different numbers next to GPB0 depending on which footprint I'm using.

Thanks!
Matthew

The attached photo:


Again, something that happens by default in EAGLE.

I'm calling my shot now: They're going to tell me to set up different part modes depending on which footprint I'm using.

I'll update when I get a response.

Update 2019-07-12

After a few messages back and forth, here's the exciting conclusion.

I got a reply 2019-07-08
This can be achieved through the following:

1. Open properties of the component.
2. Go to the Footprints section, and edit desired footprint to use different pin designator (select footprint >> click Pencil icon)
3. In the PCB model dialog, click Pin Map...
4. Locate Component Pin Designator and edit linked Model Pin designator to a different value.
5. Click OK

Therefore, the Component Pin designator is 1 and Model Pin Designator of footprint QFN would be 25.

Reference link: https://www.altium.com/documentation/19.1/display/ADES/Sch_Dlg-ImplementationMapForm((Model+Map))_AD

I hope this helps.

Well no, not really, since that's not what I was asking about.

I reply back 2019-07-09
That doesn't seem to have done what I want. When I place the component, it still shows GPB0 as pin 1. I want GPB0 to show up as pin 25 when I place the schematic symbol and have the QFN package specified. See "Pinout 2" and "Pinout 3" for examples of what I've done so far.

"Pinout 2" Attachment

"Pinout 3" Attachment
 The final reply:
 Thank you for attaching the image files. I believe your end goal is to have the symbol pins match the corresponding pins defined for each individual model where the footprint pin maps are different with each other, is this correct?

If so, this cannot be done when one component has multiple models used. Alternatively, you can take a copy of the component and paste it the number of times necessary for each individual footprint model, and then map the pins for each component uniquely.

Yes, that is what I want.

Quite frankly, this is ridiculous. Different pinouts is an extremely common thing to happen when choosing ICs, and EDA packages a fraction of the price of Altium support this functionality. I guess my next step is to post on Altium Bugcrunch for it to be ignored.

Sunday, June 30, 2019

Default Designator and Comment Font Being Changed on Me

Something odd about Altium is that there doesn't seem to be a way to set a universal font. The default is Times New Roman, and frankly, I'm just not usually a fan of serif fonts on CAD files. I'm just not used to it. Apparently you have to set the default font for each separate thing. I did that, but have still been having issues with this being reverted. Below is a message I almost sent to support:
I'm having an issue with my default fonts for designator and comment being reverted to Times New Roman.

I placed a component from the Vault onto my schematic, then to have a little more control over it, I selected it, copied, then pasted into one of my own schematic libraries. I created a footprint for it, then compiled the integrated library.

Meanwhile, I set my default fonts for the designator and comment to Arial with different justification and sizes.

When I try to place that part, the designator and comment are changed to Times New Roman 10 pt. There was another part (resistor) I copied the symbol from the "Miscellaneous Devices.IntLib". When I try to place that one, the reference designator stays in Arial, but the comment reverts back to Times New Roman. . .
The issue is that there is not an obvious way to control anything about the designator and comment other than the whole system default.

It's about this time I took one more look around, and found my solution.

While in a SchLib: Tools > Document Options...

The Properties window/pane will change and you'll see an option saying "Show Comment/Designator", helpfully highlighted below:

Wow! Look at that super useful option! I sure can't imagine why anyone might want selected as default! It's not like I might have a better idea than a dumb program of where to artfully put a designator that's close yet unobtrusive!

Here's the appropriate help article.

Altium

About a month ago I've started using and learning Altium Designer 19.1.5 as part of some extra engineering work. Up until then I've spent my entire (albeit short) professional career using EAGLE; as such, I have certain workflow habits ingrained into myself. Because of this, I am continually running into things that I find ridiculous and dumb about Altium.

To add insult to injury, this $8000 retail piece of software has bad documentation, terrible linking between pages, and even worse searching of those documentation pages. On top of that, their "bugcrunch" and forums are, as far as I can tell, unindexed, so you can't even use a good search engine.

My current conspiracy theory is that this is all done so you're obliged to re-up at $2000 a year or whatever so you have someone to ask when you inevitably run into something that shouldn't have even been an issue to start with.

As a result, whenever I'm having trouble doing something, I'm going to try to keep a record of my solutions as I find them, whether that's by clicking around, or getting help from support. These posts will probably be written assuming the reader knows the basics of Altium, so be forewarned.

Quick Update

Not that I think anyone reads this, but I thought I might go ahead and post a quick update on my life. I have some thoughts related to this blog that I may or may not continue with, but I figured this would be a good start.

I graduated from UNT in May 2016 with two bachelors degrees: one in electrical engineering and one in mathematics. For about a year all I was doing was play music and apply to jobs; I started playing with a swing band in I think September 2016 and was playing with a few other groups. I got an electrical engineering (EE) job in May 2017 and have been working there since. I'm fortunate to still have time and flexibility to play lots of music, and have recently started working there less and doing some other EE a little bit elsewhere.