Showing posts with label KiCad. Show all posts
Showing posts with label KiCad. Show all posts

2023-05-10

TX1812Z5 and WS2812B

I have used the classic WS2812B LED strips, they are very common, and AdaFruit do a lot.

They have a serial data line, in and out, on each RGB LED, and GND and 5V, making them ideal to make an LED strip will all programmable LEDs.

They work by sending a serial stream of short+long or long+short bits, 24 bits per LED, so the first LED "eats" the first 24 bits and then passes on the rest. A gap then means all done and they can all load the LED pattern. The data is around 1.25uS per bit, so even with hundreds of LEDs, this is really fast to update.

There are standard drivers, including for ESP IDF on the ESP32s I use.

But, try as I might, I could not find any of these common 5mm x 5mm "neopixel" RGB LED modules on LCSC/JLCPCB for an LED ring project. They had them on LSCS, and in stock, but would not pick up on a BOM on JLCPCB, or even allow a parts buy from LCSC, crazy!

What they did have is a much smaller, 2.1mm x 2.1mm, TX1812Z5 based, modules. And a Chinese data sheet!

So, tentatively, I designed boards using these and ordered. They are smaller, which is nice. The design was fun, C code to make circular tracks...

I was lucky - JLC queried the pin 1, as I did not (originally) have any pin 1 mark on silk screen, and only then did I realise the pin numbering for the 4 pins was different to the common 5x5 LED modules. So I was able to cancel the order at that point. Had that not happened I would have a number of duff boards!

Having got the pin out right, I ordered again. Then I had a slight panic. The LEDs are run on 5V, and hence a USB lead feeding the inner ring as 5V there. For 24 LEDs in the ring a USB-C will be fine. But, I spotted in the Chinese data sheet that min VIH is 0.7VDD which would be 3.5V, and I am driving from 3.3V data line as that works with a normal neopixel module. It was too late to cancel. But to be fair, WS2812B says 0.7VDD as well, and I know that works with 3.3V.

I also spotted that the timing was 295ns and 595ns not the timing for WS2812B which is 400ns+850ns or 800ns+450ns. Thankfully this would be easy enough to fix in software.

To my surprise, it just worked. The only issue was my PCB sandwich design is a bugger to solder the boards together. Timing and voltage do not seem to be an issue!

The project is a PCB sandwich, with top being a coaster for an (empty) fancy bottle on each table at a wedding. It is going to be awesome.

2022-01-04

KiCad 6

I am using KiCad for PCB design, and it is pretty impressive, but KiCad version 6 has just been released.

There are lots of small changes, but all good. So I checked all my designs. Some tweaks were needed.

One of the nice things is I decided to look in to was making curvy tracks - mainly for the RF board I have - the PN532 NFC/RFID reader. RF is still voodoo, so no idea just yet if this is going to be an improvement or not. Hopefully the changed boards work just as well, if not better.

PCBs are like works of art, and a bit like coding, they can be tinkered with and fine tuned over and over again. KiCad caused me to start this again.

One issue was my antenna design - a simple loop. Previously I could fudge a "line" in copper on a footprint, and as long as the line did not cross the centre point of a pad it was not spotted by the DRC. The new KiCad does spot this, and so spots the antenna is a loop that shorts things. Well, antennas do that! I have yet to work out a way to tell it that this is a special case. So I worked around it.

What I did was make the 0603 links to the antenna part of its footprint. This means the loop can be a pad design with no pin name/number, and the other end 0603 pads (usually a 0R link) are the connection to the antenna footprint. That way it can pass DRC.

But the tinkering continued...

  • Removed the separate 0.1" connection pads as they fit in the 2.5mm pads and it means less copper near the antenna.
  • Re-tracking with curvy tracks and moving some away from antenna.
  • Changing layout so the RF Rx line is "cleaner" in that it has more space around it leading in to the PN532 and no ground plane under it.
  • Changed silkscreen - cleaner - indeed the "face" has no text. Removed the component designators as they are just clutter. Various tidying. Trying to make it look "distinctive" - did it work?
  • Changed LEDs so instead of abusing normal SMD LEDs and fitting backwards (face down) I have actual "reverse mount" LEDs instead. This should mean it is possible to use in a pick and place machine.
  • Cleaning up the BOM so I can actually get a quote for sourcing and assembly.
  • I hope you like the "eyes" :-)

We know these boards work well, and all of these tweaks should do no harm, and may even improve it.

So what next?

Well, I have the reverse mount LEDs coming Thursday, so I can work out the right resistors as they are higher current - also making sure the PN532 can drive them OK. I will then get some PCBs made to test all these changes - probably an express order PCBTrain to arrive Friday.

Once I have the PCBs I'll know if the new layout works as well as before, and if the LEDs work properly and so on. The 3D case design does not even need to change!

This leave the real next step - I have a BOM that loads OK on PCBTrain quoting tool, and gives pricing. I need to talk to them as it seems more for components that direct from Mouser, but I am sure that can be sorted. As with most components there is a shit lead time, especially for the PN532 chip. It does look like it will be not as cheap as I would like, around £30 a board assembled on small ish quantities (100), maybe £20 for 1000 off. So I am interested in if people want this. My plan for now is make some and sell at cost on Amazon.

They are a cool device for any hobby project and unlike some of the other PN532 boards they are designed to be used for access control, with tamper switch button and traffic light LEDs built in, and a small 40x40 size. Also, unlike a lot of others, they have BAV99 diodes to provide more ESD protection of the pins and LEDs.


Update: Parts came Wednesday - the new reverse mount LEDs work nicely, as does replacement crystal (as one we were using is not in stock). So new board design has been ordered to test the RF side, expected Friday.

Update: The new board works nicely, so proper boards with solder resist and silk screen are due in a few weeks.

2021-03-11

Hobby PCBs

Milling PCBs

As some of you may know, from previous blog posts, I got quite good at milling PCBs. Basically, if you want to make small circuits at home, one option is a milling machine.

It does have some key advantages - the main one being time. You can have an idea in the morning, and design a circuit, layout a PCB, mill it, and have it soldered and working by lunch time. You can do several iterations of a board during a day. Another advantage is the cost - just the cost of the copper clad board, and the occasional new drill bit.

However, there are limitations. The main issue is that is it single sided - whilst a double sided milled board can just about be done, it is hard to align and the holes are not plated, so need links. The accuracy is an issue too - using a USB-C connector was just at the limit of possible, mainly as I only needed to connect two of the smaller pins (CC1/CC2), and even then - the more detail you try and do, the harder it is to get right first time.

So, moving on - what else is there? What I am doing is not quite hobby, it is more R&D, so I need slightly better than just milled board. The answer is getting fast turnaround PCBs professionally made. The nice thing is that double sided and plated through hole now becomes the norm.

KiCad

But before I could get boards made, I needed a new way to design them. For milling boards I was using inkscape to lay out the milling path. That was not going to cut it when someone wants Gerber files. So I asked Twitter, and several people suggested KiCad - a free package that was available to run on my Mac.

It is nice, I have to say. It does the schematic, and then one button and you are in to PCB layout. It has design rule checks at each stage. The PCB layout is nice - I worked out that I prefer the "push" mode where running a new track which pushes the existing ones out of the way. It has limitations, but makes it easy. The other trick I did not realise initially is I can redraw an existing track in a new direction and it will remove the original part I have now bypassed, allowing more major track moves than "push" can handle, and making it easy to do cosmetic tidy up at the end.

It also does a lovely 3D view, and it seems that not only does its built in library have 3D models for lots of things, most components have them available as standard now. Even complex modules like the Pololu D24V5F3 regulator has one. I was able to add new parts at schematic, footprint, and 3D model without any real problems.

And, of course, it will simply make Gerber files and Excelon drill files, at the click of a button.

It is also rather nice being able to design for double sided with fine tracks - it makes it way easier to track boards and allows me to make a much smaller board.

PCBTrain

So, I sent the Gerbers to PCBTrain. And two days later, they arrive. they look good.


They look nice. They are their quick turnaround product, which is copper with silver, and no solder resist or silk screen, but they work.

I even got good at soldering things like the USB-C connector.


The trick was lots of flux, and a good soldering iron. Tinning the pads first and then just heating the pin to fix it. It takes a bit of practice :-)

Tiny ESP32-WROOM-32 board

My first project to test the whole process was a minimal usable ESP32-WROOM-32 board. The idea was a board with USB-C or DC power, several GPIO on a connector, and built in serial for programming. The challenge was to make a small as possible. I think it came out well.

The result is tiny. But with 5 GPIO pins it is very flexible for all sorts of IoT applications. There is no way I could have made this on a single sided or milled board.

I also made each GPIO have pads for a pull up resistor, or, if powering something from the connector, a zero ohm link. This works well for things like a DS18B20, but could be connected to all sorts of things like an RFID reader, a GPS module, or whatever. It has enough pins that this module could run my ASR33 teletype, and be a lot smaller and neater than the node-mcu board I am using now (so that may happen).

One nasty hack was the USB connector I am using is through hole - as that makes it a lot more robust (their is nothing more annoying with these than pulling the connector off the pads by mistake). To do this I ended up with holes going through 4 of the GPIO pads on the ESP32 module. But it has a lot of GPIO, and they default to input, so no problem, as long as the software knows not to use them. Obviously I had to tell the schematic that they were grounded too.

Another trick was the the Pololu module was not fitted using pins. I could use pins and clip them short, but as it happens, with the through plated holes, just solder down the holes secures it nicely. I only use 3 of the 4 pins, as that would have put a pin through the ESP module pads too, and not in a good way this time. I did have to remember to put a pad under the 4th pin else it ended up on a GND fill which would have been bad.

The end result really is quite small.

FTDI FT230X USB/Serial

The final new bit for me was building in serial for programming. Previously I had made designs using a 4 pin SPOX connector which connected to a serial/USB lead. This takes quite a bit of board space. So I investigated serial USB chips. FTDI seem to be the king of serial USB, and they do a small 16 pin QFN-16 package module, the FT320X. I checked some videos of people soldering QFN packages by hand, and figured I'd be able to.

It is a nice small chip, connects to USB, and provides serial with Tx, Rx, RTS, and CTS as well as 4 configurable CBUS pins. It even has a 3.3V regulator, though sadly not enough to run the ESP32 - that would have been awesome!

There is one small downside - it needs a few passives. That is a pain on a small hand soldered board, and where I am trying to make it tiny (just for fun), so I built without the passives. This will mean the USB is not properly impedance matched. But it is good enough for programming in my tests, and that is all the serial lead is actually for. So what the hell? OK, yes, it annoys me to cut corners even on a fun board and I may try to at least squeeze the 27R series resistors at some point. I am not normally one to cut corners.

However, the small size, and passives, were not the only issue. I decided to connect RTS to the EN (reset) pin on the ESP32. This is a common trick and the tools, like the ESP IDF flash tool, pull RTS low and then high to reset. It is risky in a way as a "normal" serial port will make RTS low when ready for the ESP to send data, but it seems the common tools do not, so it works. What I was unsure of until I tested is that this pin stays high when otherwise idle, and when connected just to power and not a USB driver, and so on. It does. It works. Yay!

However, to program an ESP you need to put in to boot mode, and this means pulling GPIO0 low during reset. Most boards have a button for this which you have to hold when programming. Apparently some do a trick with DTR, including the ESP IDF flashing tools.

Snag! There is no DTR on the FT230X. What is extra weird is that DTR is not one of the CBUS pin modes, so you can't even create a DTR. This seems an oversight as other FTDi chips have DTR, DSR, DCD, and RI, so why are they not options on CBUS pins? Why does this matter? - well a normal serial driver will be able to control RTS and DTR as they are standard pins. To control special pins like CBUS on the FTDI needs code written specifically for the FTDI, not just any serial connection. So not using DTR makes it "special".

I considered just adding a button, but a bit more research has led me to use CBUS0. The problem then is how do you use CBUS0? It has multiple functions (not DTR, sadly), which can be configured.

FTDI EEPOM

The answer is that you programme the EEPROM in the FTDI chip. This lets you set a manufacturer, description, serial number, PID/VID, and a load of settings. One such setting is what each CBUS pin does. One of the options is a GPIO. So that is all I have to do - zap the EEPROM with the right data.

Snag! There is a tool, ftdi_eeprom, that is simple to install on a Mac. But it only lets you set a few things from a config file, and not CBUS functions. And even though it will read the EEPROM to file, it won't just write a file to the EEPROM - it insists on "building" it from your config, even bits you might have deliberately set in the file, like CBUS functions. Arrrg!

So I ended up making a tools, ftdizap, which allows me to simpley set certain (well, any) settings in the EEPROM. I also made it work the CBUS pins when set to GPIPO mode so it can control the output on the CBUS pins directly as a command line tool.

This means I can flash by using ftdizap to set CBUS0 low, then running make flash, then setting CBUS0 high and resetting with RTS low/high. It works on my Mac and on my linux machine. So, simples. A minor tweak to the make file, and I can simple make and flash new code in one go - no button pressing. The make monitor also works, leaving RTS high, allowing debug.

I also set the other CBUS pins to various modes and connected to GPIO on the ESP32. This allows the code to tell if in a "charger" mode, or if simply "not connected to a USB host", or if "put in to USB sleep mode". All of which could be useful in some circumstances.

What next

I already have another board design - this one slightly more useful. It is a small board the same size as a 1.5" RGB OLED display modules (commonly on Amazon). It fits all the necessary components between the board and the display, including a USB-C socket, and the FT230X. It has an 8 way SPOX socket so providing 7 GPIO pins. It has pads for DC power alternative to USB power. It also has pads to allow an SCD30 CO₂ module to be fitted to the back to make a complete environmental monitor. The pull up resistors on the GPIO allow it to be set up for a DS18B20, and the choice of SPOX sockets allows for a 3 pin SPOX plug connected to a DS18B20 to go in to the 8 pin SPOX socket nicely. It should make for a very flexible board.

As you can see KiCad does a nice rendering of what it will look like.

Published?

Yes, the code, and the boards, are all on my GitHub. Just bear in mind that they are likely to have several updates over the next few days.

QR abuse...

I'm known for QR code stuff, and my library, but I have done some abuse of them for fun - I did round pixels  rather than rectangular, f...