Simple 8-LED battery checker using Arduino clone board

Any old or new electronic projects on the go
User avatar
Wayne_H
Posts: 811
Joined: 17 Feb 2018, 05:26
Location: Temora, NSW. Australia
Contact:

Re: Simple 8-LED battery checker using Arduino clone board

Post by Wayne_H »

tiptipflyer wrote: 18 Aug 2022, 13:10 Thank you Martin for another great project.
I enjoy building even more than using, so I have to build one.
The LGT8F´s are on the way from China, and the case is .....(to be sorted).
Thanks for posting again.
As Frank said, Thanks from me also Martin.

Apart from sorting the case (my 3d printer she a no worka mate :lol: ), I have a number of DIP LED bar graph chips, so I was contemplating using them instead of discrete LEDs.
Cheers,

Wayne
Once a Retrobate, always a Retrobate............ ;)
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Simple 8-LED battery checker using Arduino clone board

Post by Martin »

Setting up the Arduino IDE to work with the LGT8F328P

Menu bar => File => Preferences => Additional Board Manager URLs: => click on the little 'windows' icon to the right of the text box
Add the following row of text (this may be the only row if you've not previously used boards other than the vanilla Arduino ones)

Code: Select all

https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json
Click the OK button to close the Additional Boards Manager URLs window, then click the OK button to close the Preferences window.

Menu bar => Tools => Board => Boards Manager...
In the text box near the top that says 'Filter your search...' type LGT8
You should see LGT8fx Boards by dbuezas. Install the latest version. It was 1.0.6 at the time I wrote this. Click image for larger view.
BoardsManager.png
Click the Close button to close the Boards Manager window.

Menu bar => Tools => Board: choose the options shown below. Click image for larger view.
Board.png
You may not see 'ESP32 Arduino' and other options unless you've already installed additional board managers for those. 'Arduino AVR boards' is there by default (and you'll choose that to go back to programming normal Nanos, Unos, etc.) and the one you need here is the 'Logic Green Arduino AVR Compatible Boards'.
Choose the Board: option first, and then the other Options for Clock Source, Clock, Variant, etc. will appear. Set them as shown in the image above. Make sure you set the Programmer: option to 'AVR ISP', and NOT 'LGTSWD mkII as ISP'.

If you're using the board with the square chip with pins along all four sides, then Variant: should instead be set to '328P-LQFP32 (e.g. MiniEVB nano-style and WAVGAT)'.
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Simple 8-LED battery checker using Arduino clone board

Post by Martin »

Bootstrapping a programmer.

You can't use a USBasp to program these LGT8F328P boards. You can either do serial uploads (assuming your board already has a bootloader installed, and you have a suitable serial interface), or you can use any other Arduino (including the LGT8F types as well as regular Nanos and Unos) as a programmer.

The board you're using as the programmer first needs a sketch loaded into it (LGTISP). Then you connect the LGTISP board to the LGT8F target board and use the LGTISP as a programmer in the same way you'd use a USBasp. This also allows you to burn a bootloader into the target LGT8F board, which from then on can be programmed via a serial interface.

Assuming you don't have an LGT8F board that already has a bootloader, or you don't have a serial interface for it, then here's how to use, an ordinary Arduino Nano:
  1. If you set up your Arduino IDE for LGT8F boards, turn it back to the normal Nano for now (click image for larger view).
    Nano.png
  2. Plug in your Nano with a USB cable and set the Port in the usual way. (If your Nano has previously been programmed using a USBasp, then it won't have a bootloader, so you'll first need to 'burn bootloader to the Nano, using your USBasp interface).
  3. Check that you can do a normal serial upload to your Nano, e.g. by uploading the 'blink' example sketch.
  4. Upload the LGTISP sketch, attached below, to the Nano.
  5. Now set your Arduino IDE back to being configured for the LGT8F328P, as described in my previous post, and open the nickelFourCellTester sketch, ready to upload to the target LGT8F328P board. The 'Port' option under the Tools menu should still be set to the port of your LGTISP programmer (your Nano).
  6. Link the Nano's own RST pin to its own 5V (VCC) pin (green wire in my photo).
  7. Link the Nano's D10 to RST on the target LGT8F238P board (grey wire in my photo).
  8. Link the Nano's D12 to SWD on the target LGT8F328P board (white wire in my photo).
  9. Link the Nano's D13 to SWC on the target LGT8F328P board (purple in my photo).
  10. Link the Nano's GND to GND on the target LGT8F328P board (blue wire in my photo).
  11. If the target LGT8F328P board is not powered separately, link the Nano's 5V (VCC) to VCC on the target LGT8F328P board (red wire in my photo).
    Click for larger view.
    LGTISP.jpg
  12. All the necessary pins on the target board are available on its 'programming' connector. If you're only programming the battery checker sketch, there's no need to solder a connector in - just hold the wires temporarily in place. The pins on the LTT8F328P connector are labelled on the back of the board. In my photo, front to back, they go: SWC, RST, SWD, VCC, GND.
  13. From the Sketch menu, use the option 'Upload Using Programmer', and the sketch should upload.
  14. If it won't upload, use the 'Burn Bootloader' option from the Tools menu.
  15. If Burn Bootloader fails (I've seen this with 'fresh out-of-the-box boards), hold down the reset button on the LGT8F328P board, and release it just before the bootloader burning process starts. When you get the timing right, it should work. Once you've burned the bootloader once, you should have no further need to use the reset button for subsequent programming.
  16. You can tell a LGT8F328P board that has the bootloader but hasn't yet been programmed serially, because the default bootloader 'sketch' repeatedly does three quick flashes of the onboard LED, followed by about a two-second pause.
If you have a spare LGT8F328P board and a spare serial interface to fit it, then you may wish to make a dedicated permanent LGT8F328P programmer with some flashing status LEDs. Instructions here: https://ceptimus.co.uk/index.php/2022/0 ... ogramming/
Attachments
LGTISP.zip
(14.55 KiB) Downloaded 91 times
bluejets
Posts: 317
Joined: 19 Jun 2019, 04:09

Re: Simple 8-LED battery checker using Arduino clone board

Post by bluejets »

Martin wrote: 20 Aug 2022, 10:45 Setting up the Arduino IDE to work with the LGT8F328P

Choose the Board: option first, and then the other Options for Clock Source, Clock, Variant, etc. will appear. Set them as shown in the image above. Make sure you set the Programmer: option to 'AVR ISP', and NOT 'LGTSWD mkII as ISP'.
Martin, doesn't appear to be an "Image above" to cover these settings......


Possible to run through the process for using this one that you showed earlier.....
USBTTL.jpg
USBTTL.jpg (23.39 KiB) Viewed 4260 times
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Simple 8-LED battery checker using Arduino clone board

Post by Martin »

Using a serial interface, such as the one pictured, is straightforward once the LGT8F board has a bootloader installed. The boards may be delivered with a bootloader already installed, and then you just connect your serial interface like this:

Code: Select all

Serial interface        LGT8F328P board
    DTR ------------------ DTR
    RXD ------------------ TX0
    TXD ------------------ RXI
    +5V ------------------ VCC
    GND ------------------ GND
    3V3 -- not connected
With the serial board pictured, and the SSOP20 version of the LGT8F board I used, the row of connections along one end of the board is in exactly the right order for that serial board to plug straight in, as pictured in the fourth post of this thread.

You install and set up the Arduino IDE as I described a few posts ago in my post titled 'Setting up the Arduino IDE to work with the LGT8F328P', in the Tools menu you choose the COM port of your serial interface (COM3 or whatever it happens to be on your computer), and then just upload your sketch (nickelFourCellTester for this project) in the usual Arduino way - by clicking the right-pointing arrow under the Arduino IDE title bar.

If you're unlucky, and your boards come without a bootloader installed, then you need to use another Arduino board as a programmer, as described in my previous post. You then have two choices - you can either use that programmer to directly install the nickelFourCellTester sketch to the board (Upload Using Programmer from the Sketch menu of the Arduino IDE), or you can use that programmer to burn a bootloader ('Burn Bootloader' option at the bottom of the Tools menu in the Arduino IDE). If you choose to burn the bootloader, then from then on you can program the board using your serial interface, as described above.
bluejets
Posts: 317
Joined: 19 Jun 2019, 04:09

Re: Simple 8-LED battery checker using Arduino clone board

Post by bluejets »

Thanks Martin,
I guess I'll have to do a search for the post you mention.
There is still the matter of ...

"Choose the Board: option first, and then the other Options for Clock Source, Clock, Variant, etc. will appear. Set them as shown in the image above. Make sure you set the Programmer: option to 'AVR ISP', and NOT 'LGTSWD mkII as ISP'.

or did I miss something somewhere...?? Cheers Jeff
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Simple 8-LED battery checker using Arduino clone board

Post by Martin »

You can set those options regardless of the programming method (serial interface or other Arduino as programmer). The programmer option will make no difference when you're doing a serial upload, but you might as well set it anyway while you're doing the other settings.
bluejets
Posts: 317
Joined: 19 Jun 2019, 04:09

Re: Simple 8-LED battery checker using Arduino clone board

Post by bluejets »

Point being you said set them as in image above....there was no image above for the settings...
No worries...I'll sort it..... cheers Jeff
Martin
Posts: 745
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Simple 8-LED battery checker using Arduino clone board

Post by Martin »

I can see the image, Jeff. :?: This one (click on the original of that image in the post above, for a larger view):

Image

The settings are shown in the main drop-down from the Tools menu (not the sub-menus under the 'Board:' menu item:

Board: "LGT8F328"
Clock Source: "Internal"
Clock: "32 MHz"
Variant: "328P-SSOP20 (e.g. green pseudo pro mini)"
Arduino as ISP: "Default (64)"
Port: *
Programmer: "AVR ISP"

* You can't see the port in the image, but it will be different for each user anyway - it's either the COM port number of your serial interface, or the COM port number of the other Arduino that you're using as a programming board).
bluejets
Posts: 317
Joined: 19 Jun 2019, 04:09

Re: Simple 8-LED battery checker using Arduino clone board

Post by bluejets »

Martin wrote: 20 Aug 2022, 10:45 and then the other Options for Clock Source, Clock, Variant, etc. will appear. Set them as shown in the image above.
Not in my screen..... :D ...never mind...as I said I'll sort it out.
Post Reply