I tried the Cheapest Arduino Alternative (that Nobody heard of)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
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 what 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 thousand 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 option. 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 high 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 data 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, we 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 overflows. 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 with 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 microcontroller, 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 basically 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 relatively 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 around 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.
Info
Channel: GreatScott!
Views: 441,259
Rating: undefined out of 5
Keywords: holtek, microcontroller, uc, micro, controller, arduino, alternative, padauk, atmega, project, diy, do, it, yourself, tutorial, guide, beginner, beginners, how, to, make, cheap, cheapest, budget, aliexpress, program, code, c code, ide, explain, example, show, comparison, stm, msp, teensy, raspberry, pi, pico, greatscott, greatscott!, led, input, output, blink, pwm, pulse, width, modulation, adc, analog, digital, converter, interrupt, sleep, mode, low, power, measure, i2c, distance, sensor, frequency, sketch, programmer, e-link, elink, ht66f002, ht66f0176
Id: 9IFSPqSr6t8
Channel Id: undefined
Length: 13min 31sec (811 seconds)
Published: Sun Mar 10 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.