Smart Solar Switch help.

Projects that are not for RC, but are cool and worthy of development.
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

Sounds like you would like your program broke down into bite sized tasks that you can troubleshoot independently. I broke the tasks out into subroutines. Then you call the subroutines as you get ready for them. Now you just comment out the ones you arent ready to troubleshoot with '//'.

void loop() {
//FIXME - am not checking light level nor enabling system relay
enable_heartbeat ();
check_battery_level ();
// we dont want to check the light level right now
//check_light_level ();
check_reset_switch ();
// Dont even have the relay circuit built yet
//enable_system_relay ();
check_serial_input ();
}

Too many cooks ruin the stew . I'll let the original author plot the course. But this is what I was thinking. I did verify the sketch but did not test it.
Attachments
SolarControl.ino.txt
broke tasks out into subroutines
(4.65 KiB) Downloaded 500 times

User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Thanks,
I'll give you all a rest. I have enough now to hopefully try again.
The link I posted had some analog measuring examples and circuit using a pot and one using a photocell as a level detector to turn on a led. This is close to what part of the original posted code was to do. I'll work with that to understand what's going on and then try all the files you all have posted for me.
My biggest concern is damaging the 328pu so I'll work on getting a working spare and forge ahead.
I've also been trying yo read up on all this online. I think I'll look got a good book on the Arduino applications so I can mark it up.
Thanks again everyone, I'm looking forward to this.
SM




Sent from my iPod touch using Tapatalk.
User avatar
gohsthb
Posts: 1412
Joined: Wed Dec 28, 2011 2:32 pm
Country: -
Location: Naperville, IL

Re: Smart Solar Switch help.

Post by gohsthb »

To keep from damaging your arduino, stick to low voltages for testing. Only use the 5 volts generated from the arduino itself. And always use a resistor between the pin and anything else. A book may help you get started, there are many out there. Your best reference will be arduino.cc.
-Gohst

Sent from my LG-P999 using Tapatalk 2
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

gohsthb wrote:A book may help you get started, there are many out there.
I'm a big fan of O'Reilly Books. They are my first choice for any software books. However I was unimpressed with Arduino Cookbook, 2nd Edition. When a beginner like me is finding multiple mistakes, something is wrong. And I'm not the only one. confirmed and unconfirmed errata. The author , Michael Margolis , did write the Servo library for the Arduino. Maybe due to my past experiences I have high expectations with Oreilly books, and this book didnt cut it.

Sorry I dont have a good book recomendation. But I agree with gohsthb about using arduino.cc as a reference
ReSt
Posts: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Smart Solar Switch help.

Post by ReSt »

rperkins wrote:The hex is saved, the location is dependent on your Operating system.
http://arduino.cc/en/Hacking/BuildProcess
Thanks for the link.

I now found the files to be always in the system temporary folder (never in the sketch folder) as long as the project is opened.

I was able to flash one of these hex files with AVRDUDE modifying one of the batchfiles from the voice project.
Upload speed for the original bootloader that came with my mini Arduino pro (328, 5Volt) is 57600 Bd.

Reinhard

User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

I was pleasantly surprised to get a Email from eBay that my account had some credit from a last years transaction, so I ordered 2@$3.33ea 328p-pu with boot loader and a $19 UNO rev3 with USB cable, free shipping. I should get them by February or sooner. The price for free shipping!
I now have spare 328's and a UNO to install in the solar station when I get this working.
That leaves me the original UNO to keep learning.
Sorry to read that the cook book is not cutting it.
My other option is to load up my printer with ink and paper and print out all the great info from the links you've all provided.
If there are pdf's I can download I could take them to staples and get good fast copies made since I plan to keep them in a binder.
I'm open to any used books and sources for them. Maybe that's a great thing to add to this topic, links and books we "should" know about since we've already had some reviews.
This week as time permits I'm going to follow up with friend, and the robotic club group for hopefully some one on one or group class on this locally.
They must have recommended reading or maybe library recommendations, or their own materials.
I freelance and got a call to work this week so my lab time is limited, but I'll have some extra Hobby money!
That's where a book comes in handy. My iPod touch is great for everything on the go except for reading large articles on its 4" screen.
I've got everything I need now except a "clue" to what I'm doing ha ha. I bet that's been obvious from the start.

My plan with this solar project is to first get the low voltage detect code and hardware working. Next the photocell detect. Then put it all together as originally posted.
Hopefully doing this I'll be familiar enough with it all to be able to tweak the program to do what I need it to do.

With 5 working modified Frsky 9x TXs, 2 of those with different rev's of the sky boards, and a 9XR stuck in a Chinese post office, I'm a little board. My planes fly great and don't seem to crash!

This Arduino project is exciting, like the first er9x/telemetry mod I did several years ago.
SM






Sent from my iPod touch using Tapatalk.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Smart Solar Switch help.

Post by jhsa »

My planes fly great and don't seem to crash!
I think you should never say that :mrgreen: :mrgreen: :mrgreen:
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Midairs YES! Radio failure since going to Frsky from Spektrum NO!
The rule is always fly an ugly plane and nothing will happen to it. It must be true because I'm seeing more and more ugly planes that don't seem to crash, for some it would be a blessing however. :oops:
SM
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Smart Solar Switch help.

Post by jhsa »

yeah, you seem to fly in a very busy airspace :D
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Busy isn't the half of it. When I take off I always ask right to left or left to right! Everyone give a different answer, landings are even more exciting! It's not a private field so that's normal. Learn to fly with Master Card or Visa as your tutor these days. :?:
The crashes are to behold however so it's not all bad. Car hoods, golf course, pit areas, everywhere but on the field except for the straight down from 100 ft into the paved part of the runway. Now that's a crash! :lol:
Ok, enough. I'm sorry for their losses but it does thin out the herd, shame on me! :oops:
SM
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

gohsthb wrote:This should get you started. This program will only allow charging while the sun is up. Also if the battery voltage goes low it will disable people from charging, until the battery voltage recovers + 1 hour. The program expects a light sensor (analog) and a battery voltage divider. At the top of the program are some 'defines' so you can set the trip levels and a hysteresis. Once you have the sensors connected you can test them through the Arduino serial monitor, where it will show you their values on request. Use that when setting up the defines. Let me know if you have any questions.
I saw your other Arduino post, the answer to your first assignment is in this code.... :mrgreen:

-Gohst
I can use some more help please.
I’m finally getting to this project.
A few dump question before my request.
To drive the relays or external leds do the get pulled to 5 volts or down to ground when they are activated? I understand I may need current limiting.

Is it possible to please break the program down so that of course the onboard led blinks, but without the solar detect to start? What I want to do is just use a pot as a voltage divider into the A1 input and try and get the digital output led and relay 12 and 2 to toggle when I rotate the pot from 5v to ground using the UNO 5 volts into A1.
Can I just pull A0 to 5 volts so the program will be happy as it is?

To be sure, what syntax do I insert in the program to have it skip that operation and just pass thru to the next one?

I’ve been reading and trying to find examples to do this but any help in that would be great.
Thank you everyone for any fast track help.
SM
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Is this what I do to skip operations

x = 5; // This is a single line comment. Anything after the slashes is a comment
// to the end of the line

/* this is multiline comment - use it to comment out whole blocks of code

if (gwb == 0){ // single line comment is OK inside a multiline comment
x = 3; /* but not another multiline comment - this is invalid */
}
// don't forget the "closing" comment - they have to be balanced!
*/
SM


Sent from my iPod touch using Tapatalk.
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

Showmaster. did you get a chance to look at the sketch I posted ? It broke each task down into a subroutine . all the subroutines but one can be commented out with a single line comment '//'

ps. it looks like the outputs are active high. so there is 5v on the relay output when the relay should be energized.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Somehow I missed the sketch. I'll reread your posts. Thanks for putting up with my questions while I educate myself. Thanks for the voltage state info.
SM


Sent from my iPod touch using Tapatalk.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Ok found the sketch. It was right there where you posted it. Dumb me, thanks.
I'll give it some serious study.
SM


Sent from my iPod touch using Tapatalk.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Strange happenings?
I'm stumped but not giving up.
I loaded the sketch into my UNO R3 board.
I changed the timeout timer to 15000 ms for test purposes.
Here's my test setup. I have a 5k pot across the UNO boards +5v and ground. The center wiper goes to A1 input (low battery voltage simulation).

I have a jumper from A0, to the UNO +5v buss.(the solar panel detection input).

I have a green led in series with a 470 ohm resistor to digital out 2 ( relay simulation). The led cathode goes to ground.

I have a red led in series with a 470 ohm resistor to digital out 2. This is the led relay on indicator. I'm not sure about this connection but I for now the cathode connects to out 2 and the resistor and and anode connects to +5v.

When I turn the pot from outputting 5 v to about 2-3v I do get the green led to turn off to simulate turning off the relay. The red led does do something?

What happens next is wierd?
Of I turn the pot to output 5V again the green led (relay) doesn't light again until I touch the UNO board?
I have 2 boards and they both act the same way. I'm thinking the board(s) are maybe going into oscillation and my hand stops it?
I'll scope it tomorrow.
Should I be loading the outputs or inputs more? Can I leave any unused inputs and outputs unloaded?
Meanwhile the blink led keeps blinking right along so at least that's solid.

Ok, enough fun for tonight.
SM
ImageUploadedByTapatalk1359358188.280161.jpg

Sent from my iPod touch using Tapatalk.
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

ShowMaster wrote:? Can I leave any unused inputs and outputs unloaded?
yes

The rest of it I dont know about ?
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Ok thanks. It's a start. I won't worry about unused pins.
I'm going to put this on hold and try and go through some of the on line material again focusing on the analog in and digital outputs.
There are some utube videos I found also.
What's bumming me is not being able to find any Arduino books locally to look over or any at the library. I hate ordering one online to find out it's not worth the high price.
I'm still trying to hook up with the local robotics club meetings but they seem to keep losing a place to meet at.
This is just a setback and I'm not giving up. I bought several spare 323p's with a bootloader installed so I can trash a few getting up to speed.
More when I have something positive to report.
Thanks again for you help.
SM


Sent from my iPod touch using Tapatalk.
ReSt
Posts: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Smart Solar Switch help.

Post by ReSt »

Unused digital inputs should be set to a clear logic level.
This can be done by wirering them to + or ground (see the edit at bottom) or by activating the pullup resistors of the inputs.
Floating digital inputs should never occur because you never know what they are doing.
And they are sensitive to touching them.
The danger is, an 'analog' voltage on a digital input can make the logic draw very high currents.

That's my state of knowledge.

Reinhard

edit:
It is not recommended to connect inputs directly to + or ground as it could happen, that the input sometimes temporarily may become an output.
Last edited by ReSt on Mon Jan 28, 2013 9:11 am, edited 1 time in total.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Smart Solar Switch help.

Post by jhsa »

SM, did you try removing the Red LED to see if the Green LED stops foolin' around and do it's job properly?? It might be a silly idea, but it is so simple that it worth trying it ;)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

ReSt wrote:Unused digital inputs should be set to a clear logic level.
Reinhard
Thanks for correcting me. I had not noticed any problems but see you are correct. This link also shows how to enable the internal pullups

http://arduino.cc/en/Tutorial/DigitalPins

What's unusual is none of the tutorials I have used show external pullups on the unused pins nor do they explicitly enable the internal pullups. Maybe I missed those too as I know I have read the digitalpin tutorial before :)
ReSt
Posts: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Smart Solar Switch help.

Post by ReSt »

Just found this.
Connecting the pins directly to ground or + is not recommended!!!

Unconnected Pins
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even
though most of the digital inputs are disabled in the deep sleep modes as described above, floating
inputs should be avoided to reduce current consumption in all other modes where the digital
inputs are enabled (Reset, Active mode and Idle mode).
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up.
In this case, the pull-up will be disabled during reset. If low power consumption during reset is
important, it is recommended to use an external pull-up or pull-down. Connecting unused pins
directly to VCC or GND is not recommended, since this may cause excessive currents if the pin
is accidentally configured as an output.
User avatar
rperkins
Posts: 1422
Joined: Sun Jan 08, 2012 12:51 pm
Country: -

Re: Smart Solar Switch help.

Post by rperkins »

Since the arduino IDE configures pins as input by default. Wonder if unused pins have the internal pullup turned on by default ? Doesnt sound like it.
User avatar
gohsthb
Posts: 1412
Joined: Wed Dec 28, 2011 2:32 pm
Country: -
Location: Naperville, IL

Re: Smart Solar Switch help.

Post by gohsthb »

Here is a new version of my above sketch. I disabled the light level checking for you. I also changed the timer to 10 seconds. This is the timer that runs after the battery has gone low. You were probably having problems because the light level detection was active but not attached to anything, hence you could touch the board and make it work. I also added more comments into the code for you.

Here is the basic operation of the code:
do setup
-configure output pins, load battery level and light level variables, enable the serial interface

in loop:
Blink the heartbeat LED - 1 second on 1 second off

check the battery level - set the flag as necessary, or reset the timer

(light level check would go here)

Check if the relay should be on or off

finally if you send a 'v' over the serial connection respond with battery and light level

end of loop

You can leave unused inputs floating. They don't cause problems unless you are reading them for some reason. And the high currents drawn are only high if you are on a battery powered system.
-Gohst
Attachments
SolarControl.ino.txt
(5.15 KiB) Downloaded 428 times
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Thank you so much. I makes sense to me from the way it's broken down.
I'm ok with the concept. A friend suggested I stop by a college or JR college bookstore and see if they stock any books on Arduino?
It's been years since I've done that? It can't hurt.
SM


Sent from my iPod touch using Tapatalk.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Good old Radio Shack had a $15 book. It's a start!
ImageUploadedByTapatalk1359411659.760895.jpg
SM


Sent from my iPod touch using Tapatalk.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

Making Progress, at last!
This was the key
"ReSt wrote:
Unused digital inputs should be set to a clear logic level.
Reinhard"
and this link on pull-ups and downs.
http://arduino.cc/en/Tutorial/DigitalPins.
As soon as I used a 10K pull-up to 5 v on the reset 3 it all started to work as planned and make sense. This was the port pin that when I went near it the circuit would sort of work before but I didn't know what was happening at that time.
I need to learn how to turn on the pull-ups in the sketch for the reset and other unused pins now.
My test setup using the shetch with the 10 second delay is doing what I thought it should using a 5K pot to simulate low battery. I haven't messed with the solar detect yet, that's next.
Thanks everyone, I’m crawling now but maybe I’ll be standing soon ha ha.
User avatar
gohsthb
Posts: 1412
Joined: Wed Dec 28, 2011 2:32 pm
Country: -
Location: Naperville, IL

Re: Smart Solar Switch help.

Post by gohsthb »

Are you using an Arduino board. Our just an atmega plugged into a breadboard? The Arduino board should already have that resistor on it.
-Gohst

Sent from my LG-P999 using Tapatalk 2
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

gohsthb wrote:Are you using an Arduino board. Our just an atmega plugged into a breadboard? The Arduino board should already have that resistor on it.
-Gohst

Sent from my LG-P999 using Tapatalk 2
I'm using a real Arduino UNO board.
There are no resistors I can see on those pins but I understand there are commands to turn on ones internal to the 323p?
I printed out the r3 UNO schematic and it doesn't show any resistors on those connector pins.
The link above to the Arduino site discusses all that.
Interesting is that the latest UNO project book I just bought doesn't mention the command or needing pull up or down resistors on unused inputs or outputs.
Hopefully more persons reading this will have more hands on experience with all this and help.
So far the info posted has gotten me moving forward at last.
Thank you all.
AN


Sent from my iPod touch using Tapatalk.
User avatar
ShowMaster
Posts: 4327
Joined: Thu Dec 29, 2011 3:44 am
Country: -
Location: Los Angeles, CA USA

Re: Smart Solar Switch help.

Post by ShowMaster »

I found this in the link material
Pullup Resistors
Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input, with 10K being a common value.
There are also convenient 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed in the following manner.
pinMode(pin, INPUT); // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors

I'll have to try these commands.

The only trouble was the reset input 3.
It floats if the switch isn't pushed and is very high impedance. This I guess is why my hand would influence it. The 10k pull up makes sense now.
SM


Sent from my iPod touch using Tapatalk.

Post Reply

Return to “Other Electronic Projects”