Show Posts
Pages: 1 2 3 [4] 5 6 ... 579
46  Using Arduino / Project Guidance / Re: "External" memory for program memory? on: April 08, 2014, 06:40:07 pm
Quote
Here i have an IF to each day of the week.
With AFAIKT identical code for every day, why not put that code into a function so it only appears once, and why compare hours, mins and tpa every time when it's just the day that changes?

Quote
by initialised data?
Yes, the file A_Textos.ino has a huge number of strings, one array has 256 of them called texto0 through to texto256, then you have an array of 256 pointers to them

Code:
char* tabela_textos[] PROGMEM =
{
  texto0, texto1, texto2, texto3, texto4, texto5, texto6, texto7,
  texto8, texto9, texto10, texto11, texto12, texto13, texto14, texto15,

Just put the strings in an array to start with.

Then there are a lot of near duplications

Code:
prog_char nomecanal12 [] PROGMEM = "ALTERAR POTENCIAS DOS LEDS BRANCOS";
prog_char nomecanal13 [] PROGMEM = "ALTERAR POTENCIA DOS LEDS AZUIS";
prog_char nomecanal14 [] PROGMEM = "ALTERAR POTENCIA DOS LEDS AZUL ROYAL";
prog_char nomecanal15 [] PROGMEM = "ALTERAR POTENCIA DOS LEDS VERMELHOS";
prog_char nomecanal16 [] PROGMEM = "ALTERAR POTENCIA DOS LEDS VIOLETA";

This could be split to "ALTERAR POTENCIA DOS LEDS " (is the "S" needed on the first string?) and the colour string, that way the large part of the string will only occupy space a single time.

How about this
Code:
         bled_out  = map(NumMins(t.hour,t.min),(NumMins(led_on_hora,led_on_minuto) - amanhecer_anoitecer), NumMins(led_on_hora,led_on_minuto), 0, pwm_pre_definido);
         wled_out  = map(NumMins(t.hour,t.min),(NumMins(led_on_hora,led_on_minuto) - amanhecer_anoitecer), NumMins(led_on_hora,led_on_minuto), 0, pwm_pre_definido);
         rbled_out = map(NumMins(t.hour,t.min),(NumMins(led_on_hora,led_on_minuto) - amanhecer_anoitecer), NumMins(led_on_hora,led_on_minuto), 0, pwm_pre_definido);
         rled_out  = map(NumMins(t.hour,t.min),(NumMins(led_on_hora,led_on_minuto) - amanhecer_anoitecer), NumMins(led_on_hora,led_on_minuto), 0, pwm_pre_definido);
         uvled_out = map(NumMins(t.hour,t.min),(NumMins(led_on_hora,led_on_minuto) - amanhecer_anoitecer), NumMins(led_on_hora,led_on_minuto), 0, pwm_pre_definido);

The value assigned to these variables is exactly the same but you repeat the humungous map() code for each one.

The entire code is rife with this sort of thing, it should be totally refactored, but as you say "my programming knowledge does not allow me to do it." so the only options I can see are to learn better programming technique, pay someone to modify the code, or get a larger platform.

______
Rob
47  Development / Other Hardware Development / Re: Shield designs - which idea first? on: April 08, 2014, 06:12:03 pm
Quote
A high precision ADC with memory
How high precision? And what's the memory for?

______
Rob
48  Using Arduino / Project Guidance / Re: How can I use spi to emulate this? on: April 08, 2014, 10:05:09 am
There are clones that use the Saleae software, maybe as cheap as $15, have a google for them.

Like this http://sigrok.org/wiki/MCU123_Saleae_Logic_clone although I don't know what it costs.

______
Rob
49  Using Arduino / Project Guidance / Re: Automatic plant watering system on: April 08, 2014, 09:40:41 am
Those 9v batteries are not very good at supplying large currents, I suspect they and not up to the job of driving that motor.

You can prove that by monitoring the voltage when you connect the motor, I bet it drops significantly.

Get a battery with more grunt.

______
Rob
50  Using Arduino / Project Guidance / Re: How can I use spi to emulate this? on: April 08, 2014, 09:11:52 am
Quote
Do you have any suggestions of what should i buy?
If you are referring to a logic analyser the best little LA around IMO is the Saleae Logic.

https://www.saleae.com/

______
Rob
51  Using Arduino / Project Guidance / Re: Automatic plant watering system on: April 08, 2014, 09:08:04 am
Quote
This is how I just hooked it up just to test it
You used bagged milk?!

Quote
But now when I hook up my 9V nothing happens
Quote
Any solutions?
Hint, is the pump from a 9V car?

______
Rob
52  Using Arduino / Project Guidance / Re: How can I use spi to emulate this? on: April 08, 2014, 08:50:42 am
Quote
The LA is an arduino based.
Oh, then get a real one smiley

I think you can use the normal SPI.transfer() function and wiggle that enable pin yourself with digitalWrites(). That last trace could be done something like this

Code:
byte bytes_to_send[] = {1,2,3,4,5,6,7,8,9};
#define N_BYTES (sizeof(bytes_to_send) / sizeof(bytes_to_send[0]))

digitalWrite(enablePin, HIGH);
delayMicroseconds(100);
digitalWrite(enablePin, LOW);
SPI.transfer (bytes_to_send[0]);
digitalWrite(enablePin, HIGH);

for (int i = 1; i <  N_BYTES; i++) {
     digitalWrite(enablePin, HIGH);
     SPI.transfer (bytes[i]);
     digitalWrite(enablePin, LOW);
     delayMicroseconds(100);
}

Very rough and who knows is it is what the device needs re timing etc, but you could play with that until it looks the same as your trace.

______
Rob
53  Using Arduino / Project Guidance / Re: "External" memory for program memory? on: April 08, 2014, 08:35:26 am
Yikes, I don't have time to trawl through all that, but here is an example

Code:
      stash.println((millis()/1000)/60);
      stash.print("Z,"); // Potência aparente
      stash.println((millis()/1000)/60);
      stash.print("ZA,"); // Fator de potência
      stash.println((millis()/1000)/60);
      stash.print("ZB,"); // Tensão RMS
      stash.println((millis()/1000)/60);
      stash.print("ZC,"); // Corrente RMS
      stash.println((millis()/1000)/60);
      stash.print("ZD,"); // Frequência
      stash.println((millis()/1000)/60);
      stash.print("ZE,"); // KWh
      stash.println((millis()/1000)/60);

Why call millis() and do that maths every time, do it once then print a variable.

setup() has a gazillion pinModes() in a row, use an array of pin numbers and a loop.

checktpa() has a humungous amount of duplicate code, maybe that could be reduced. For example

Code:
  if ((segunda==t.dow) && (hora==t.hour) && (minuto==t.min) && (tpa == 0))
  {
    tpa=1;
    if ((4294967295ul - tempo) < millis())
    {
      marcadoriniciotpa= millis() - (tempo*2);
    }
    else
    {
      marcadoriniciotpa= millis();
    }
  }

  if ((terca==t.dow) && (hora==t.hour) && (minuto==t.min) && (tpa == 0))
  {
    tpa=1;
    if ((4294967295ul - tempo) < millis())
    {
      marcadoriniciotpa= millis() - (tempo*2);
    }
    else
    {
      marcadoriniciotpa= millis();
    }
  }
// and another 7 times I think
The only difference between these is the variables being compared I think, at least put the body of the if() block in a function, but why do you do the same thing with different tests?

I'm sure this code could be substantially reduced, but unless you have finished it it will just grow too big again so a more capable platform may still be the answer.

______
Rob
54  Using Arduino / Project Guidance / Re: How can I use spi to emulate this? on: April 08, 2014, 08:15:47 am
Just looking at the data sheet for that CPU it seems that the SCI port is really just a version of an SPI port. I suspect they are transmitting bytes much the same as you do on an AVR and bit-bashing the enable signal with a GPIO pin.

As to why the enable for the first byte is a different polarity to the rest I have no idea but you could replicate that functionality yourself.

______
Rob
55  Using Arduino / Project Guidance / Re: How can I use spi to emulate this? on: April 08, 2014, 08:06:37 am
See how different it looks with a better sampling rate? You'll have to learn how to drive a logic analyser.

Quote
At higher rates I can`t get anything.
Eh? How could it not work if sampling faster? What brand LA is it?

Anyway it looks like SPI with an active high CS to the slave device...except the first byte in which the enable signal is low.

Got me beat, I think some documentation is required.

______
Rob
56  Community / Bar Sport / Re: Your latest purchase on: April 08, 2014, 07:08:10 am
Quote
ring-pull can top to cover the quartz window.
smiley

And all before Photoshop.

Quote
negatives, photo paper, darkroom, enlarger - remember them?
Too right I do, I worked in darkrooms for years, B&W printing was my first real job.

______
Rob
57  Using Arduino / General Electronics / Re: atmega328p-mu and plcc32 sockel on: April 08, 2014, 07:04:34 am
If it was a PLCC32 then yes there are many cheap sockets, but it's not it's a QFN so you are out of luck. You either learn to solder them or get a breakout board.

______
Rob
58  Products / Arduino Due / Re: Arduino Due vs. Propeller-2 on: April 08, 2014, 07:01:28 am
Quote
TBD KB RAM for Program Storage
How does the Propeller load it's code?

______
Rob
59  Using Arduino / Project Guidance / Re: "External" memory for program memory? on: April 08, 2014, 06:59:07 am
Quote
use to expand flash memory of the my arduino mega 2560?
The Rugged Circuits expansion board was for RAM not flash, on an AVR there is no way to execute program from external memory AFAIK.

If your program really needs to be that big you better start looking at a different platform. It maybe that you could optimise it a lot, but at that size I'm not going to suggest that you post your code smiley

______
Rob
60  Products / Arduino Due / Re: Building my LCD library for Arduino DUE on: April 08, 2014, 06:55:05 am
Nice

______
Rob
Pages: 1 2 3 [4] 5 6 ... 579