Suggestions on how best to interface between ubuntu (laptop) and Arduino

Hi all, this is my first post here. I am newly back to programming and would appreciate help on how to set up a program to control a mechanical system. Here's what I have:

  1. Two separate single axis solar tracker rows with solar modules, a motor and a 3-axis accelerometer on each row
  2. Arduino Leonardo controlling the tilt of the tracker (I manually set the tilt angle in the IDE, upload the entire code to the Leonardo, and it adjusts)
  3. NREL spa.c code to calculate the sun position running on the laptop that I'm uploading the Arduino code from

What I want to do is run the NREL code every minute (I know it is overkill) to calculate the sun position. Then, automatically feed a "desired" angle to my Arduino so that it will adjust each tracker row to face the sun. I cannot load the NREL code onto my leonardo because it will exceed max memory.

So, my plan is:

  1. Loop the NREL calc on my computer with a 1 minute delay
  2. Write a script in the C-code to modify the desired angle in the Arduino code
  3. Write another script in the C-code to upload the modified code to the Arduino

Does this sound reasonable? Any other thoughts on how to do it?

Thanks,
Camelman

Also, I expect this post will be helpful for communicating between the Arduino and laptop.

http://forum.arduino.cc/index.php?topic=225329.0

For obvious reasons I think that the code in that link is a wonderful way to communicate between an Ubuntu PC and an Arduino - that's where I developed the demo. There is also a simpler version of the code in Reply #4.

Do you really need NREL data and acceleromters? Perhaps you love that sort of stuff?

All you really need to align solar panels with the sun (assuming, of course that you have a suitable mechanical and motor arrangement) is a pair of Light Dependent Resistors (LDRs) per axis. Just ensure the sun only falls evenly on both LDRs when the panel is directly facing the sun. Then whenever the Arduino detects that one LDR is in shadow it moves the panel a little towards the other LDR.

Of course this also means that you don't need to send data from the PC :slight_smile:

...R

Robin,

I hope you think your code is wonderful! :slight_smile: I need to use the NREL algorithm for this project because I am demonstrating a modified approach to tracking for utility-scale systems. At the utility scale, every 1/10th of a percent of production is huge money, and photo sensor trackers just don't have sufficient accuracy.

I spoke with a robotics friend about this last night and he suggested running everything in C rather than using the Arduino IDE. That sounds great to me, except I'm such a novice in C that I don't think it will be time-efficient for me to try to control the Arduino directly from a C program on my laptop. So, I'm sticking with my original plan of using C to modify and upload the Arduino code file. This is how I hope it will work:

  1. Execute the NREL C code to determine the optimum angle, but with the following actions
  2. open the Arduino code file
  3. find/replace the previous tracker angle with the newly calculated angle
  4. save/close the Arduino code file
  5. load the updated Arduino code onto my Arduino Leonardo
  6. delay for one minute and repeat

I'm seriously a newbie to this, so please weigh in if you have a better idea on how to do this. I absolutely need to run the NREL code, so please keep that in mind.

Thanks,
Camelman

dahabas:
he suggested running everything in C rather than using the Arduino IDE.

The end result would be just the same. Some professionals think things are better if they are difficult.

I'm not familiar with the NREL calculations - which may explain this question.

Is it your intention to do the NREL calculations on a PC and send the result to the Arduino whenever it is necessary to adjust the angle of the solar panel?

Your notion of uploading new code to the Arduino every minute (which is what I think you mean) does not make sense. For one thing you will wear out the Arduino flash memory where programs are stored. All you need to do is arrange for the PC to send data to the program which is running continuously on the Arduino. That way the Arduino could get new data every few seconds if needed.

By the way, I remain to be convinced that complex calculations updated every minute would be any more effective than a direct sensing system that can update as necessary.

...R

I had forgotten about that wear issue with the flash memory. So, from what you are saying I can command the Arduino to query the computer for an update, or search for an update from the computer. That makes much more sense, but means I have more learning to do.

Regarding sun sensing vs. angle calculation, the issue comes in when you are dealing with multiple rows of solar modules. In fact, it is easy to exceed 500,000 solar panels in large installations. If you know your row spacing, slope, compass orientation and row width, then you can align the module rows to capture maximum sunlight without shading neighboring rows. Shading is key here because shading a small portion of a solar module can cut out over 20% of generation of that module very easily and adversely affect generation from other modules feeding into the same inverter. This gets worse as more modules are shaded, which is what happens when one row shades another. Sun tracking systems that are not coordinated with neighboring rows cannot control shading, and do not have the accuracy to perfectly align towards the same point. Also, there is not always a clear line of sight to the sun due to clouds, so a sun sensing controller will struggle with ideal tilt, which increases the likelihood of shading. For a single row application, a sun sensing control system is fine. It just doesn't work out so well when you go to multi-row installations. This is my industry. :slight_smile:

Camelman

dahabas:
it is easy to exceed 500,000 solar panels in large installations.

That's a little bit beyond my experience - I have 3.

The demo of Python-Arduino communications in Reply #4 here may give you an idea of how to exchange data. You will need a special program running on the PC to interface with the Arduino. However that need not be a complex program.

...R