So while working on the code for the control board part of the receiver project, I came across an interesting conflict. The keyboard and the rotary encoder did not want to play nice with each other than and the compiler was spitting out an error about a vector conflict. Keyboard worked fine by itself and the rotary encoder worked fine by itself but put the code for both into the once program and the compiler went bonkers.
So i set about learning everything i could about interrupts on the Mega 2560. And this was where the fun began and i ended up going down a rabbit hole from which i was lucky to escape. Well i did survive and i did actually learn about interrupt vectors, pin change interrupts and external interrupts and a little about library conflicts along the way.
So this is not really a tutorial on using interrupts or the differences between pin change or external, but rather a rant about the 2 hours I spent last night reading and trying to understand what I had done and why there was a conflict. In the end it was because i programmed the rotary encoder to use pin change interrupts and it was the library i used that was in conflict with the keyboard library. I did not know that was what i had done, i had assumed that using pins 18 and 19 on the mega, being the external interrupt pins just worked in one way only. But no no no, they can be either external or pin change interrupts depending on how you code for it. Yes, a very rookie mistake.
So after finally working out what I had done wrong, or in reality why the libraries were in conflict, i changed 2 lines of code and had the rotary encoder working as it should be with the keyboard and everyone is happy. So at the moment I have a working keyboard, rotary encoder and VFO and now that my work week is done, I will hit the code hard tomorrow and make some real inroads into getting features in there that I want in my radio. Its not going to be as pretty as the Nextion vfo codes that are floating about the internet, but its going to be all mine. And sometimes, its good to know you have rolled your own and it does what you want.
Easter has been quite productive for me, this is project 3 out of 4 is rechargeable battery powered arduino clock with temp and humidity function. Nothing fancy, but highly practical and accurate. The code is a mess, but i have shared it down below, i know someone out there can clean it up and make it more efficient, but for now, its working and doing what it needs so, show the temp and the time.
Hardware is kind of inefficient for this task, arduino mega and 3.2″lcd are both overkill and power hungry. There is an RTC and temp humidity sensor, 18650 battery, boost and charge controller. As usual i did a really crap job at cutting the hole out, I really should have done this in the CNC, I might even make a how to video on how i do that later today.
#define DHTPIN A0
#define DHTTYPE DHT22
TFT_HX8357 tft = TFT_HX8357();
DHT dht(DHTPIN, DHTTYPE);
const long interval = 60000;
unsigned long previousMillis = 0;
bool Century = false;
unsigned long currentMillis = millis(); //Do stuff here every 60 seconds
if (currentMillis - previousMillis >= interval)
previousMillis = currentMillis;
tft.setCursor(10, 10, 1);
if (L_Date < 10)
if (L_Month < 10)
tft.setCursor(30, 100, 7);
if (L_Hour < 10)
if (L_Minute < 10)
tft.setCursor(20, 280, 4);
tft.setCursor(260, 280, 4);
humid = dht.readHumidity();
temp = dht.readTemperature();
L_Hour = Clock.getHour(h12, PM);
L_Minute = Clock.getMinute();
AmPm = "pm";
AmPm = "am";
L_Date = Clock.getDate();
L_Month = Clock.getMonth(Century);
L_Year = Clock.getYear();
L_Year += 2000;
DAW = Clock.getDoW();
DayOfWeek = "Sunday";
DayOfWeek = "Monday";
DayOfWeek = "Tuesday";
DayOfWeek = "Wednesday";
DayOfWeek = "Thursday";
DayOfWeek = "Friday";
DayOfWeek = "Saturday";
DayOfWeek = "ERROR";
What a day, what should have been a simple job, for a simple man turned out to be an all day endeavor to overcome a litany of problems. In other words it was a fucking disaster. LOL but hey, i got there in the end and now the weather station is about to be put back out in the weather to do its thing. So lets see, what went wrong, well the sensor i was using was different from the previous one, so i needed a different library, then the device address was different to what was in the code, then the micro controller I was using shit itself and died, then i had problems with my computer not recognizing USB devices, then the board library was being a pain in the arse and needed upgrading, and finally there was this problem with crashing because dumb arse here created an array and was causing a stack overflow because the array had no size.
Well, after all that, I now have a pile of crap on my bench destined for the bin and a nice space on my bench where the weather station used to be. This time i have spares and should be able to fix things if something breaks without having to wait months. Its been down for 5 weeks, and thankfully its back up and running. For now, touch wood. LOL. Now I need to create a page that will query the database and display the data.
Its been a while since i have posted anything to do with electronicals and as i have been tinkering with the its been taking forever weather station i thought i would post an update.
The major change has been to the power system. I found these rather cool Wemos 18650 boards that take care of charge, voltage boost etc etc for a couple of bucks. The specs are perfect for all sorts of projects and will match up perfectly with the 6V solar panel i have to go with this and will charge at a max of 0.5amps. The cheep lipos have a combine capacity of 3.5amp hours, and the project atm draws about 0.1 amp hours, so good for say 30 hours without sun, which in Brisbane should be more than enough, if not I will buy some real lipos and use them instead, but, once i start dropping the micro into standby, that current draw will drop dramatically.
I have the code all working for the modules installed, humidity, temp, pressure, rain, I still have Lux and UV sensors to install. The code will poll the sensors every 15mins, save the data to SD card and push a copy of the data to my home server where I am still working on a web interface and graphing to display the data. High and Low data for the day is saved at midnight and pushed to the home server also.
And not to be outdone, I have even done some woodwork and 1/2 built a house for this which will then get installed in the garden. Also I have coming from china a rain gauge and depth module for measuring how much rainfall there has been, the rain sensor i have in the above image just detects rain, not how much or how intense it is.
I ran into a little bit of an issue with the old power management system i had installed. The original design was to use a buck converter to drop the battery voltage to 3.3v, this worked fine except the micro controller would not run with 3.3v it needs 5v, so much for reading the manual which said it ran on 3.3v. So then I added a boost converter, except that the BMS would shut down when it was connected.
So onto plan C, i ripped out the BMS, the charge controller and the converter, and am now using an all in 1 unit that is designed to work as shield board for the wemos mini. USB cable will run to the solar panels to charge the lipo’s, the jst connector goes to the batteries and power out is from the 5v pin on the shield. Yeah its ugly, but will work. The 3.3v needed for the sensors will all run off the regulator on the micro. Its a mess, but will work.
Now that crap is sorted, its time to finish off the code and make it work. Thats a job for another night.
So like all good things we have to start at the beginning, downloading and installing IAR Embedded Workbench.
And now we are done.