Get $60 New Customers Coupons & Try JLCPCB at low cost: https://jlcpcb.com/AAA
Join our group to get the instruction of Multi-Color Silkscreen PCB: https://www.facebook.com/groups/JLCPCB
You can get the Holtek Microcontrollers & Programmer here: (affiliate links)
HT66F002: https://s.click.aliexpress.com/e/_DCUCVMD
HT66F0176: https://s.click.aliexpress.com/e/_DDV19wN
E-Link Programmer: https://s.click.aliexpress.com/e/_DlsY8bL
You can download my created code here:
https://www.patreon.com/posts/holtek-code-99366052
Previous video: https://youtu.be/SG0eWf_Cbw0
Register Manipulation video: https://youtu.be/EVm0qVJ56II
Timer video: https://youtu.be/IdL0_ZJ7V2s
Facebook: https://www.facebook.com/greatscottlab
Twitter: https://twitter.com/GreatScottLab
Instagram: https://www.instagram.com/great.scott.lab/
TikTok: https://www.tiktok.com/@greatscottlab
Discord: https://discord.gg/zuAvkAuhsY
Support me for more videos: https://www.patreon.com/GreatScott?ty=h
In this video we will be having a look at another Arduino Microcontroller alternative: the Holtek Microcontrollers from Taiwan. These are some of the cheapest microcontrollers you can get and they offer lots of useful features. So how easy are they to program and would I recommend using them? Let's find out!
Useful Websites for Holtek Programming:
https://www.instructables.com/Getting-Started-With-Holtek-Microcontrollers/
https://www.holtek.com/webapi/116711/HT66F002_0025_003_004v230.pdf
https://www.holtek.com/webapi/116711/HT66F0176v131.pdf
https://www.holtek.com/WebAPI/Holtek_e-Link_for_8-bit_MCU_OCDS_User_s_Guide_En.pdf/84d53516-918f-4b14-a087-5c47381cfe3a
https://www.holtek.com/WebAPI/UploadFiles/Documents/Media/HoltekDataMigration/188787/Holtek_e-Link_QA_Ver103_EN.pdf
https://cika.com/soporte/Information/Holtek/Microcontrollers/8-bit/DevTools/HT-IDE3000_ProgrammersGuideClanguage.pdf
https://www.bestmodulescorp.com/dev16nsop002.html
https://www.holtek.com/webapi/116745/an0446e.pdf
Thanks to JLCPCB for sponsoring this video.
Visit https://jlcpcb.com to get professional PCBs for low prices.
0:00 I need a CHEAP uC!
1:40 Intro
2:30 What features do we need?
3:42 HT66F002 Feature Overview
4:17 How to Program it?
5:15 Output Feature Blink
7:07 Input Feature
7:48 PWM Feature
9:04 ADC Feature
10:07 Sleep Mode (Low Power)
10:45 I2C Problem!
11:53 Verdict
Now here is the problem; this right here is
part of a big project I am currently working on. We got an infrared distance sensor, an Arduino
Microcontroller and an LED and as you would have guessed, the closer we get to the distance
sensor, the brighter the LED gets. Sounds simple enough; but the problem is that
for the big project I need to build this setup 14 times and that can get expensive. Now using a cheaper distance sensor is not
possible and I actually think its price is justified for wha
t it can do. But we do not need such a big Arduino board
or its Atmega328P Microcontroller because it is way too overpowered with all of its
features and also costs around 2$ per piece. So I searched through all corners of the internet
to find a cheap alternative and I think I found one in the form of the HT66F002 that
only costs around 0.2$ per piece which is a noticeable price difference. That of course sounds amazing; but the next
problem now is that unlike Arduino, for which there exists tho
usand of tutorials and libraries,
this microcontroller barely has any beginner guides available. So the question is whether I can make this
microcontroller work for my project and that is exactly what we will be finding out in
this video. Let's get started! This video is sponsored by JLCPCB, whose PCB
service I used for many years and projects now. Their online platform is user friendly, easy
to navigate and best of all, you can receive your PCBs in just a week by using their fastest
shipping op
tion. If that sounds like your cup of tea then you
can order their premium quality 1-8 layer PCBs starting at $2 or even try out their
3D printing service starting at just 30 Cents. And last but not least let me tell you a secret,
that their colorful silkscreen PCBs are coming soon. So stay tuned. Now let's start off with finding out what
the microcontrollers needs to be able to do in my project. The simplest thing would be using the pins
as inputs and outputs meaning they can pull their pins hi
gh or low as an output to for
example blink an LED or they can detect when their pins are getting pulled high or low
as an input. Then we need to create a PWM signal with variable
duty cycle which looks something like this on the oscilloscope. This is definitely mandatory to dim the brightness
of LEDs. And while we are at it, maybe it would be
helpful to read the analog voltage of a potentiometer to dim the brightness of an LED accordingly
which means we need an analog to digital converter. And
last but not least a sleep mode would
be beneficial to save a bit of power and of course we definitely need to be able to use
the I2C communication protocol to obviously communicate with our distance sensor. So yeah these are the main features I need
for my project and to find out whether my cheap microcontroller here can do them all,
I firstly checked its datasheet. And yes; it seems like pretty much all functions
are in theory possible to do, except one that I will address later. And of course
when comparing these specs to
all the microcontrollers I already had a look at before; then it is definitely not a power
house but certainly the cheapest option I ever looked at. So to get started with it, I firstly soldered
it onto a breakout board and next had to actually get myself another piece of hardware for it,
which is its dedicated programmer; the e-link. According to its manual you only need 4 of
its pins for programming which are VDD and GND for power and OCDSCK and OCDSDA for the
da
ta lines. Connecting those to the microcontroller was
luckily super straightforward since the datasheet clearly states what pin connects where. And just like that it was time for programming,
for which I firstly had to install the HT-IDE3000 and the HOPE-3000 software. Now the IDE software is used to basically
write your code; pretty much just like the Arduino IDE. And the HOPE software is then used to upload
your created code to the microcontroller. And with that out of the way let's create
our
first project called blink, select the HT66F002 and let's get started with coding
a blinking LED. Now in Arduino language this is as simple
as defining a pin as an output, pulling it high and low and waiting a bit in between. And luckily for me with the HT IDE it is not
really hard to do either; the commands are just a bit different. For example with pac1 = 0 we set the pa1 pin
seen here as an output and if we would say pac1 = 1 it would be an input. And by then pulling this pin high and low,
w
e should basically have a blink sketch, right? Well, sadly after compiling this code and
then uploading it by clicking download which worked wonderfully though even at the first
try, my LED didn't feel like blinking properly. Now I probably spent around half a day figuring
out what the problem was and tried solutions like decreasing the output current, adding
capacitors and so on. Eventually though I realized that the watchdog
timer was the problem which provides a device reset when its timer ov
erflows. So after disabling it, my blink code finally
worked like intended. And in case you are wondering what this code
line here means then it is basically used to alter the watchdog timer register which
I will need to do quite often with others registers as well. So if you want to learn about that then definitely
check it out in one of my previous videos. But anyway, next it was time for a push button
input to for example turn on an LED which with the Arduino and its digital Read function
was
super easy to do. And once again with the HT IDE, it was also
fairly simple to pull off; the only new function here is the papu one which enables a pull
up resistor at the defined input pin. So after building this circuit up and uploading
the new code, it worked perfectly fine meaning the first mandatory feature was ready to practically
use. Time to move on to the PWM one which if we
look at Arduino programming is once again easy to pull off, by using the analog write
function in combination wi
th an 8 bit value that constantly changes here to control the
brightness of the LED aka the duty cycle of the PWM signal. When it comes to HT programming though this
matter is definitely a whole lot more complicated because here we have to set up all the mandatory
timer registers manually. Eventually though I ended up with a functional
piece of code and the duty cycle can be changed here with a 10 bit variable. And after uploading this code you can see
that it works just like the Arduino one and
even features a higher frequency in direct
comparison which was only around 490Hz before. Of course you could achieve a higher frequency
with the Arduino as well by manipulating its timer registers and if you want to do that
then check out my previous video about timers. But anyway, PWM works and it was time for
an analog input aka a potentiometer and I feel like a broken record here by saying that
Arduino makes it super simple to use this function. With the cheap microcontroller though it took
me around 3 hours to manipulate the right register and then use bit math to store the
final analog voltage value in a variable that I can then pass over to the PWM function. But as you can see that was worth it in the
end because I ultimately got it to work. And I think generally it is simpler to program
with Arduino because there you got a serial interface meaning you can check at every point
what the value of a certain variable is which makes troubleshooting so much easier. With my cheap micr
ocontroller, I can not do
that; so it was a lot of trial and error. But either way; ADC works meaning low power
was next and here it was luckily easy to realize; since this halt command puts the microcontroller
into sleep mode and by defining one input as a Wake Up input, you can bring the microcontroller
back to life. Here you can see the final example which after
blinking 5 time goes into sleep mode where I got the microcontroller current demand down
to 11uA and by pushing this button, we basi
cally turn it all back on and repeat this process,
nice. And that brings us to the last I2C feature
which my small microcontroller is sadly missing. But luckily there are dozens of Holtek Microcontrollers
out there and this HT66F0176 apparently comes with I2C and only costs around 30 Cents per
piece. So after soldering it on a breakout board
and making sure that everything still works by uploading my PWM sketch, it was time to
dig into the I2C function. But sadly after around one hour I realized
that this microcontroller along with apparently all other Holtek 8-bit microcontrollers I
could get a hold on, only supports I2C in slave mode; but for my project I need it as
a master. This basically shattered my goal of using
these microcontrollers for my project and truth by told I only realized that after spending
3 days getting used to its programming. So was this video pointless in the end? I think not because now I know that the Holtek
Microcontrollers are not only cheap, but also relati
vely easy to program for and yes the
IDE looks like Windows 95 but it is simple, free and does it job just fine. Combine that with the fact that they make
lots of application specific microcontrollers like some for smoke detection, BLDC motors
or even with a 24 bit ADC and you got yourself some pretty compelling advantages here. But on the other hand though the programmer
for the 8-Bit microcontrollers is quite pricey for a hobbyist and like I said before there
are not many libraries or guides a
round which are all in all my main complains here. But if you want to use them for yourself then
definitely check out the video description where I linked all good guides I found as
well as all the code I created in this video and a bit more. With that being said it is time to find another
cheap microcontroller for my project and I think I already know what I will try next. Until then I hope you enjoyed this show and
maybe consider supporting it through Patreon to keep it going. Don't forget to
like, share, subscribe and
hit the notification bell. Stay creative and I will see you next time.
Comments
It was so close to programming in raw assembly code that you might have been able to bit-bash your I2C functionality. Even on the smaller chip. The watchdog was the first thing that came to mind when I saw the way the LED was behaving. Every time you move to a new microcontroller there's a bit of a learning curve.
Watchdog timers are brilliant when used properly - deserving of a video of their own. Basically, inside your loops you reset the timer. If your program crashes, it won't reset the timer and the watchdog circuit will reset the whole device. Absolutely fantastic for circuits that aren't easily accessible in particular.
I feel like a little RISCV chip makes a lot of sense here, like the CH32V003. It’s even cheaper than your $0.20 part and can work as an I2C controller.
This just makes me appreciate the rp2040 even more. They work with all standard stuff and what they deliver for below 1$ is just absolutely crazy.
I came across the Attiny85 recently after many years of projects with atmega328s and it certainly has made a difference for smaller projects for both cost and size.
If you have GPIOs and are using PWM through a timer, it's not too difficult to implement i2c master in SW, much less simple to implement slave which is probably why they have it on some versions.
I2C master is trivially simple to bit-bash, no need for a hardware peripheral
The programming pin names OCDSDA and OCDCLK do hint at On Chip Debugging, the IDE even has a Debug menu. It might support breakpoints, much better than using Serial.print
in our microcontroller programming course we had to program like first few weeks in assembly language - it really made people appropriate how much higher level languages with proper libraries enable people to do with much less effort
Thank you so much for videos like this, Ive built so many projects with my school counselor and saved my school a lot of money this way
You should be able to use the programmer to debug as well, just like an Arduino. Usually there are functions that allow you to write to the serial bus, which should even show up in your Arduino IDE if you pick the right port.
Great to see you're using my Instructables guide! To be honest I never thought anyone would read it 😂 I've been using Holtek for years mostly on commercial products and always found them great for the price. Keep up the great videos! On another point, maybe you could bit-bash the I2C, but it will be a difficult task.
Very nice! I'm so glad you documented this process! Learning that the process ultimately did not achieve what was hoped makes is just as valuable as learning a process that does achieve this.
You are truly an inspiration for me. You gave me the courage to start in electronics in my late 30's as a hobby and I really enjoy it. Thank you 😊
As someone whose interest in microcontrollers predates the Arduino, I'm always worried about how that "easy mode" could affect the collective skill level of this field. I'm glad you're shining some light on other options. Also worth noting, it is entirely possible to write your own I2C code. Not _quite _ as trivial as SPI, but still well within reach of a hobbyist.
A great alternative could be the attiny series (not the 85 but their newer attiny chips). They are available in 8 to 24 pin packages, with 2 to 16kB memory and come with SPI, I2C, UART, multiple timers with either 16Bit or 8 Bit pwm, and adc and much more. Im pretty sure you can also programm them with the arduino ide and an arduino nano if you dont want to fork over 160€ for microchips own programmer.
I feel like something from ST probably would fit the bill pretty well they have some really low cost small boards and the HAL and arduino compatibility make it easy to start things up
Nice vid! Not sure why you didnt mention that you can implement a bit banged i2c master! No need to have it as a hardware module, specially at lower speeds
Ben Eater has an EXCELLENT series about building a PC from scratch, including the evolution from code bytes to assembly instructions, all the way up to C code which is a great complement to this info.
Yep. Right on schedule: Exactly at 6:45 of a 13m30s video (50.0%) the 'Blink' is finally working. I've said this for years: Getting 'Blink' (or 'Hello World') to work is typically the halfway point of any small project in any new µC ecosystem. Not usually so precise. That's why Arduino, which includes 'Blink' from the start, has such an easy learning curve. Everyone should understand this point; it's important for planning and scheduling.