Arduino UNO is going to help me to control some measurement system. In my analog part of project I'm using filter in which the cut of frequency has to be aligned with outer signal which I'm generating with Arduino. Nevertheless I would like to display the current cut off frequency (I use the potentiometer to set it) on standard LCD ( Hitachi HD44780) .The part of code which handles the recording data on SD card works well but there is problem with displaying the value of cut off frequency on LCD. The first value is being displayed, but in the second loop I have some ugly characters on LCD. Also if I display the value f.e from potentiometer separetedly it works fine. Maby this problem is somehow connected with interrupts which I use to control the program, but on the other hand interrupt itself seems to work. I enclose the code. Please, help me. Best regards,
I don't understand your code; a is set to an analog read (value 0 to 1023) then a is set to map... ???
then set_frequency (a). Also serial.begin is commented out but you use serial.print
Regardless, what happens when you print to the serial monitor just before the lcd print? Same strange characters there?
You may wish to only print to the LCD when your value changes, then you won't be printing to the LCD every time through the main loop...
Yes, I've tried to put 1 second delay after lcd.print commnad im loop and I doesn't help at all. As fas as code is concerned: mapping value from ADC is used for adjusting values of useful frequencies and commenting Serial.begin() was made to check whether or not it has something to do with problem of displaying proper digits on LCD. Evidently it doesn't so I still have no clue how to deal with my problem...
You attach an interrupt to pin 0 and when pin 0 is falling you call function.
I didn't see the code for the interrupt service routine (function).
What if you detach the interrupt, do your analog read, print to the LCD, then attach the interrupt again?
In your example, does the serial monitor print correctly or garbled as well?
The interrupt function is defined in 20th line of my code and it just iterates, so that the program knows which procedure it is suppose to do (recording or setup the frequency), hence the modulo in if() structures. I just want the program to react differently on successive button press (two states). After detach the whole procedure of interupt (commeting attachInterrupt() in setup()) there is no diffrence - after a whille of proper digits I see only rubbish and then after some time the LCD is just like cleared, everything dissapears. What's strange, the serial monitor displays consecutive values correctly.
I do think that if your information displays properly in the serial monitor but not on the LCD. The LCD is the problem. Maybe post a few pictures of your hardware setup and your garbled screen as compared to the serial monitor. A video would be cool. Then maybe one of the other experts here can help you.
Hello,
I've recently figured out the genesis of my problem. I think it's connected with the function set_frequency, where some Atmega registers are set to provide the CTC mode for my generator. It seems to me that those registers also participate in LCD handling procedure and can be just overwritten continuously. Maby changing the timer for generator will solve this problem...
I've recently figured out the genesis of my problem. I think it's connected with the function set_frequency,...
Good thinking!
Arduino digital pin 10, which is used by the LCD, is Pin 2 of port B.
Your instruction 'DDRB = 0x06;' is affecting this pin as is anything else that uses this pin. What is the purpose of that instruction (your code has no comments) ?
The most important thing for me is to use the CTC mode in Arduino's Atmega to generate the square wave but I also need the LCD to oversee the value of the frequency. I had an idea that the major factor that contributes to problem is function "DelayMicroseconds" which is used in the LiquidCrystal library. Hence I wanted to replace every DelayMicroseconds (in library) with "while" or "for" loop with particular amount of itterations (in my opinion the accuracyin this case is not of big importance). However another problem seems to appear, because those loops don't work properly as they should - regardless of the amout of itterations time between actions is the same. I checked it using the Logic Analyzer. So this solution just doesn't work. I have no idea why is that...