Thursday, January 19, 2023

Light Buddy - The PCB

 

Got my latest PCBs on Tuesday.  I knew before they arrived I had a problem.  I assumed (should be a four letter word) that PPS would allow any function on any PPS pin.  Well PIC18 may come close to that, but PIC32 does it in blocks.  So now I have 10 boards that are really not very useful.  Fortunately the USB and the console port could be used.  This one is very similar to the Brick Controller I cant build for lack of parts.  The Motor interface is missing and the BT (RN4871) is superset of the BT (RN4020) module on that Brick Controller.  The PIC32 is from the same PIC32MX family, just in QFP44 instead of a QFP64.  So this one is a high end LED controller with 15 LED channels.  I had previously mentioned this. 

I started pushing code into it, using the previous BrickController and MPLAB X Harmony Project I started.  Just in case the startup code for this PIC32 was unique.  Amazingly the USB HID came up right away.  I could not move data back and forth, but the PC recognized that a HID device was connected.  On the next day I was moving data and my Win10 App was talking to the device.  There were some USB connection issues.  They may have existed before I just never noticed them, but I decided to make this rock solid.  The PIC32 USB/HID implementation is more flexible than the PIC18 and this is OTG, which I am not using.  There are 3 state machines at the App level, two of them are callbacks from the USB/HID driver implementation.  The third is the real App level state machine.  It took a few days to get this working.  It was a simple matter of getting all three state machines in sync with each other and realizing that the two callbacks were actually running as the result of ISRs and those totally asynchronous to the App it self.

Once the USB/HID was working, merging in the other code for the other peripherals is easy.  Will need some conditional compiles, I dont like maintaining multiple code bases if I dont have to.

More later.




Wednesday, January 18, 2023

Sewing Room - More Storage

The next step in this upgrade is to provide storage around the Sewing machine cabinet.  As a side effect, I also need to provide support for the sewing machine cabinet extension arm.  Too many years of excess weight and little boys playing on it while bothering their Mother.

Here is the first step.  Installing a Kallax 1 x 2 and 2 by 2 bookcase, side by side.  This is placed so that the electrical plug on the left is still usable and such that there is space for the sewing machine cabinet extension arm and its needed support.

I used some material similar in thickness to the base board, to provide support and as a place to secure the bookcase to the wall.  This material was attached to the studs in the wall.  Then I could use the standard IKEA wall connections as I did on the large bookcase.

Next I framed the corner to support the sewing machine cabinet extension table. 

And here is the extension arm down.  The used is undecided about the gap.  The sewing machine cabinet extension is just under 3/4".  So matching it might be hard.  Plus whatever fills the gap needs to be very smooth, since you would not want it grabbing the material and "picking" at it.

Underneath the extension arm is a 1 x 2 Kallax bookcase.  As before, with the baseboard, there would be a 1/2" gap at the top.  That is just an invitation for small things to fall in.I framed the tip of the bookcase with the same material as the baseboard.  Added some white paint to the framing edge so that it is not as apparent.  I also rounded off the corner that goes into the wall corner, makes that fit better.  The sheetrock inside corner is not perfect. The gap on the narrow end of the bookcase is larger than I wanted.  If this proves to be an issue, then I will caulk the gap against the wall.  Right now the only thing holding this in place is the compression fit of the sewing machine cabinet pushing the bookcase against the wall.

Here is the finished look.  Now unfortunately the left side of the bookcase is probably not usable.  The gap between the two bookcases is about 4".  The intent is to place larger rulers, cutting boards and other tools that are large in the X and Y direction, but have no depth.

 

Next step is the cutting table that comes out the wall and in the center of the room.

 

 

 

Tuesday, January 17, 2023

Solar Shed - Realized

My original plan was to build a perf board proto with the LT1085 and the relays.  Then after some thought I decided  I needed to add multiple ADC inputs.  The PIC ADC does not like high impedance inputs.  I had lots of low bandwidth (<15KHz) OP_AMPS that would provide the buffer and a low impedance input to the ADC.  These MCP6031 are set up as unity gain buffers.  The input is scaled down depending on the input voltage range.  

Well using these SOT-23-5 parts made perf board very hard.  One of the PCB fab houses I use was running a special of $5 (plus shipping) for 4" by 4", qty 5.  Thus it made since to make a PCB.  Easier to build and more reliable.

Here is the board.

 
This the board next to the Curiosity HPC Development board.  The daughter board will plug into the connectors on either side of the processor.
 
 

Here is the unpopulated daughter board attached to the Curiosity HPC.


Here is the daughter board assembled. 

These are the major parts of the daughter board.

  • LT0185 with 100uf 50VDC capacitors on the input and output. I have lots of these capacitors, so I decide to use them.  They are excessive in size and capacity, but they are free.  The LT085 takes in the solar panel output and generates the 14.4VDC charging voltage.
  • Two 12 dual latching relays that control connection to the battery and the LED lighting in the shed.
  • Some N-FET buffers for the PIC outputs that control the Relays,
  • The MCP6031 OP-AMP buffers.
  • A LDO that converts battery voltage to 5VDC for the Curiosity HPC.  In turn the Curiosity HPC converts this 5VDC to 3.3VDC.
  • The necessary connections to the Solar panel, battery, light switch and LED light power.





Monday, January 16, 2023

Sewing Room - Upgrade

 A complete change of pace, adding more storage to the sewing room.

The upgrade will consist of multiple wall storage units from IKEA.  This time I am using the Kallax bookcases as the base.  The first wall unit is this one.

This consists of 5 by 5 on the bottom and two 2 by 2s on the top.  The top is done with a gap in the middle.  The two top bookcases were attached using standard sheet rock type screws as shown here.


Then all three bookcases are attached to the wall using the standard hardware provided by IKEA.  Except i move the bookcases locations so that the screws would go into the studs in the wall.  This makes the three sections act as one piece now.

 
 
In order for the bookcases to be flat against the wall, the baseboard had to be removed as can be seen here.



The next issue was the switches on the wall.  There are three switches
  1. The overhead electrical box.
  2. The half hot electrical box in the wall.
  3. The fan electrical box.
The overhead electrical box was for the track lighting I put in.  this provides adequate task lighting for all for the two main work areas.  Putting up eight foot tracks on a 10 foot ceiling was a challenge, but it is done. Included my wife standing on a step stool with a broom, trying to hold 8 foot end in place while I attached the other end.



 
One of the vertical walls of the 5 by 5 bookcase went right over the switch plate.  I cut a small notch in it so the book case would sit flat against the wall.  But this made one of the switches inaccessible.  Fortunately this was the fan switch, so I just removed it.  Permanently connected the fan and placed a blank off plate with a note to remind me the fan is always connected.


That left the track lights and the wall half hot which has stand lamp connected to it.  Since these are at the back of a cubby, either the space can't be used or switch access will be limited.  I already have a Lutron Caseta wireless system in the house. I installed On-Off Caseta switches for the track lights and the stand lamp, as seen above.  Then I installed two PICO remote controls on the side of the bookcase as shown here.

This provides a user experience that is the same as a normal wall switch.  Now the original wall switch access is not needed and thus the cubby can be used.  If access is ever needed, we just clean out the cubby.  The notch in the book case provides enough space to remove and install the switch plate.

The track light connection in the ceiling is the only 120VAC connection in the house that had not been tested.  I changed out the mechanical switches for two smart switches, they are not dimmers just switches.  The down side to these is they require a neutral wire, fortunately code up here says the neutral has to be brought to the switch box.  I have installed about 8 of these now, the first 7 went perfect.  The switched plug one worked as expected.  But the track lights would not turn on.  If I took a light out of the track and put it back in, it came on and the switch would turn it off. But would never turn it on.

I did not even want to think that the wiring was messed up.   I started thinking the switch was dead, or could not handle the LED track light or the wiring came loose or something.  So I disconnected the track lights at the ceiling, wired the track lights to cord with a plug and plugged into the switched outlet.  It all worked with a smart switch.  Thus it had to be somewhere between the switch in the wall and the ceiling connection.  This meant removing the wall palate and pulling the switches out of the box.  It could have been worse.  All the connections were solid, nothing had loosened or slipped out of a wire nut.  So I disconnected the offending switch and just hot wired the ceiling box.  And it worked.  Well the wiring is good and that is a good thing.

 I reconnected all of the wires just to  be sure.  As a last resort, I go to the LUTRON site ( LUTRON Caseta Smart Switches) to see if they have any sage advice.  First thing on the list is reverse the two black wires.    I have installed 7 of these without even a thought about which black wire goes where, with no issues.  My track lights work.  I had a 50-50 chance and  got it right 7 times.  Maybe I should play the slot machines. 

And this is done.






Friday, January 13, 2023

Light Buddy 1 - The Design

I have been working intermittently on a new Brick Controller, that I documented in multiple blog posts, this being one of them.  Well since parts are impossible to get, I moved on.  Got a quote from one of the robber barons for the LED controller (TI LP5569) with an MRSP at Digikey of $1.65 in qty 1.  They wanted $55 for an MOQ of 25.

Below is the result.  Not sure I can get everything for it right now, but it will be good enough for demo purposes.  There was no way I was going to build any of my new Brick Controller.  So I switched to an LED controller.  This is a subset of what the Brick Controller was, just no motor control.  This made power much easier since I did not need to make 9VDC.  The LEDs are powered from VUSB, ie directly from the USB bus.  The PCB is 48x64mm and is designed to fit exactly on a 6x8 LEGO plate. 





The differences from complete design freedom are:

1.  Had to put in a new BT module, the one I have been using (RN4020) is not available for years if ever.  MIcrochip does not appear to be upgrading it for BT 5.x spec from 4.2.  The BT SIG has deprecated 4.2 already and wont certify any 4.2 after 1/1/2023, according to the Microchip website when you look at the old BT module.  This BT module(RN4870/RN4871) is BT 5.1 but the smaller version cant be found, so I am using the larger version.  I have about 15 of these I bought months ago as a hedge.  They claim firmware compatibility, we shall see.

2.  The processor is a PIC32 of the same family as the new Brick Controller and I am hoping the firmware changes will be minimal.  There seems to be lots of these floating around.  Hopefully tomorrow they will still be there.

3.  If you look carefully you will see a small square IC (U1).  That is the LED controller (LP55231).  This a previous version, but is firmware compatible with the one (LP5569) I used on the new Brick Controller.  I bought 20 of these months ago from one of the robber barons.  For whatever reason they were only 3x in cost.  The biggest issue for me is that this controller is a source to the LEDs while the newer version is a sink.  While this might not seem like a big deal, it actually has large implications in the wiring of a LEGO display.  At least I try to minimize the number of wires running through a LEGO build.  Using 36-42 gauge wire, you want to minimize the number of wires that can break.  So in my case, I minimize the number of source wires since this is the common wire.   All my previous designs used an N-FET to sink drive the LEDs, that way I can parallel up multiple LEDs and not worry too much about the current load.  So I added N-FETs to the output of the LP55231.  I give up the current control the LP5569 provides, but I use PWM to control intensity anyway.  With the VUSB supplying the drive voltage, a 120 to 150 ohm resistor provides the necessary current to brightly light the LED.  When the LP5569 controller becomes available, those N-FETs and one resistor per channel will go away.

4.  I added 5 more LED channels using the 5 PWM controllers in the PIC32.  These would normally control the motors, but they work nicely with LEDs also.  So this gives me 15 LED channels, which sounds like a lot, but I can get very carried away with lighting effects.

5.  I added 4 inputs, 3 digital and one analog.  Though the analog can be made into a digital.  The 3 pin connector has 3.3VDC, ground and input to either a Schimdt Trigger or an unity gain OP-AMP.  This shroud provide all the input I can use.




Thursday, January 12, 2023

Solar Shed - A Beginning

The Controller

As a distraction from my long term projects, I decided to start working on a usable version of the Solar Charger for the Shed. Right now it is just an LT1085 3 terminal regulator set to 14.4VDC. The Solar Panel puts out up to 24 VDC Open circuit, but will fall dramatically when current is drawn. So the LT1085 output just follows the input with a 1.5 volt drop when the input voltage drops below ~16VDC. When the battery is fully charged, it seems to trickle charge just fine at 14.4VDC.

My idea for this is to add some relays and a PIC to monitor voltage. When the battery voltage gets to 14.4VDC, the solar panel/ LT1085 is disconnected. When the battery drops below 14VDC, the panel is reconnected. Or some numbers similar to that. The idea is to protect the battery from excessive voltage. This is basically what a battery charging circuit would do. Just an extra safety check so I dont have to worry about this.

Time to move on to a design I can install.  This is definitely a one off.  Thus I am looking for an inexpensive solution.  I have multiple Microchip Development boards that I no longer use, so that seems like the place to start.  Additionally I have several OLED displays.  

The Development board I chose was the CURIOSITY HIGH PIN COUNT (HPC) DEVELOPMENT BOARD, DM164136.  This has a PIC18F47K40 ( which cannot be bought right now, maybe later in 2023).  This has two MIKROE CLICK board sockets on it, which goes well with the several OLED Click boards I have.  So I started out to get the OLED to work, then I would need to build a small perf board addon for the LT1085, relays and connections.  This seemed easy and quick. 

Well......................the first step took over 3 days on and off.  I could not get the OLED to display any text.  The FONT file is placed in program FLASH memory, because it is much bigger than the available RAM on this PIC.  I finally drilled down into the C compiler generated assembly code to watch the TBLRD opcode always show a read of 0x00.  I double checked the FLASH to verify the FONT file was there.  Something kept nagging at me that I needed something else to make this work.

Off to search the Internet.  After tooooo many hours, I stumbled on a comment that you need to read the errata.  In this always useful document, was a known defect on one version (my version of course) that the TBLRD opcode did not work unless a certain two bits in a certain register were set correctly, not the reset value as the data sheet says.  And then it came back to me that I had the same problem before with this PIC and the Dev board the first time I did this. For some reason the fix was not in the code I thought worked when I started this a few days ago.

In the end I am now going to package up the OLED code and place it in the repository so I have this for future OLED Projects

And just to make it more fun, I spent one morning trying to understand the color pattern.  It has a 5-6-5 (RGB but maybe BGR, SW controlled) pattern to keep it to 16 bits and 65K.  But it is also inverted this pattern in the OLED controller, so you have to put the inverted value in.  Too many variables, but i found the right order and the bit pattern to finally get something out of it.  Plus there were some hard coded sections in the driver that needed fixing from the last time I worked on this.  But I am declaring victory.  I got 4 lines, with no reading glasses required, and about 8 characters, which should be enough.  R-G-B is OK, but the intermediate colors are off.  Last line is supposed to be yellow and white looks awful pink.  The OLED also has a burned in pattern at times from previous use, which might be why the intermediate colors are off.  But again, good enough for this.

And here is the chosen OLED, (OLED-C MIKROE 1585) working.


 



Wednesday, January 11, 2023

Android Updates

Well once upon a time, it was very easy to develop, test and push into the PlayStore.  I guess Google became jealous of Apple and its layers of requirements.  At som epoint I do understand that they need to have standards, but these updates every year are time consuming for the single person developer.   I spent the last 3 days trying to move one app (TDust) into the play store.  Now part of it is truly my fault for not keeping the apps up to date.  So trying to move from API 24( #7) to the new required API 30 (#11) and 64 bit versions has been fun. I can test on Adroid 7,8,11 and 12 with the devices I have.  I actually went to Best Buy and bought an unlocked phone.  It was $165 if you activate it and $165 if you dont.  Naturally I did not activate.  It is more a less a mini tablet.

I had already done the Permission thing before, but Google keeps changing the permissions required.  When permissions were implemented, to use BLE you need to have location permissions. I suppose it is because there is small possibility that the location of the phone can be determined.  But this changed as the APIs advanced.  First it was coarse location then fine and now coming in API 31 (#12) no location as long as you swear on someone's grave you wont use BLE to find the phone's location.  Actually they are completely revamping the permissions around BLE it looks like.

I am only complying with API 30 and the new App bundle requirement for now.  This is good for new apps until Aug 2022 and Updates until Nov 2022, at which point it is API 31/32.  With the price of gas, I assumed I would not be making many trips this summer, but that did not happen as we were gone much more than planned.  

When I went all the way to API 30, it all failed big time.  The program crashed, the debugger failed, it was a mess.  So I went back two revisions on the Embarcadero Delphi compiler, API 24 and the last set of code that worked from SVN.  That worked on all the devices, though Android complained a lot when installing on the newer devices. So I slowly marched up the API list.  One thing I did was create a separate code module to handle the permissions.  That way once I figured it out, it would hopefully work for all my programs.  When I got to API 29 (#10) I had to switch the compiler version, since the older version did not support API 29(#10).  This is where permissions started changing and I had to research what was happening.  After two days I finally got it all working on API 29.  I am now one step away.  At this point I had to move to the latest version of the compiler.  This caused quite a few library types to change, but I was smart enough to implement conditional compilation so that I could go back and forth on the compiler versions.  This proved useful as API 30 did not come easily.  But after a day of searching and changing, the app finally worked on all the devices with API 30 as the target.

Then uploading to the Play Store became another fun thing.  You cant upload APKs any more they have to be in the new App Bundle format. And now signing/encrypting the App is not good enough, the upload has to have a key also.  They can be the same, but they recommend against it.  Well I converted my existing key to the format they wanted but could not figure out how to generate a separate upload key.  So for now they are the same.  Supposedly I can change the upload key, I just cant change the App key.  I uploaded the app and then the Play Store went nuts about a permission, background location.  I had read the it was now required, but they wanted to know why I was using and to provide a 30 sec video showing how it was used.  Then a week or so they would get back to me.  So I deleted the upload, went back removed the permission and tested again.  It all seemed to work.  Upload this new version, no complaints and it was published.

But it cant end here.  I then tested the install on the devices. The older devices were still installing the older version, don't know why.  Something I have to look into.  But the 64 bit version just crashed on start.  So back to the devices.  The compiler keeps separate configs for debug and release.  I had failed to test the 64 bit release version.  Found a setting in the 64 bit release config that was wrong.  Once that was fixed, the 64 bit devices started working.

I still need to find out why the new 32bit version is not installing.  You would thing this is not a big deal, but............  The Samsung A13 I bought at Best Buy is an ARM8 64 bit, but they installed the 32 bit version of Android.  So even if Google is screaming 64bit to everyone, some of the big guys are still installing 32 bit OS, even on 64 bit ARMs. 

Next is the API 31/32 update due in Feb 2023 now.