Show Posts
Pages: 1 [2] 3 4 5
16  Using Arduino / Programming Questions / Using PROGMEM data on: February 15, 2013, 08:20:01 am
I was reading the reference about PROGMEM data (http://www.arduino.cc/en/Reference/PROGMEM)
and I've found in internet examples using thing like this:

Serial.println(PSTR("this is a test"));

But I've also found this case:

Serial.println(F("this is a test"));

I'm tried both in one program where has ram problems, and found that the second case works better. My question is what is the difference? In which case should I use each one?

I've also seen some places where they uses P() instead of F()

I've found that there is a very usefull sprintf_P() function that can use PSTR() as parameter but if I use F() instead, the compiler reports an error.

17  Using Arduino / Programming Questions / Declaration of progmem constant string on: February 08, 2013, 01:41:52 pm

I am trying to declare a progmem string just like in the documentation (http://arduino.cc/es/Reference/PROGMEM)

I wrote a little program like this:

Code:
prog_uchar signMessage[] PROGMEM  = {"I AM PREDATOR,  UNSEEN COMBATANT. CREATED BY THE UNITED STATES DEPART"};

void setup(){
}
void loop(){
}

And when I try to compile, I receive this error:

sketch_feb08b.ino:2:26: error: variable 'signMessage' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

¿Any ideas on what is the problem?

(I'm using Arduino 1.0.3 under linux).
18  International / Hardware / Receptor de termómetro inalámbrico 433Mhz on: December 04, 2012, 11:35:58 am
He estado haciendo un programa para recibir la transmisión de un termómetro inalámbrico. Ya lo tengo funcionando pero como he visto que no hay mucha información al respecto, y que este tipo de termómetros parecen bastante comunes porque son muy baratos, les paso a continuación el programa final y un link a la descripción completa que he puesto en internet. Espero que les resulte útil:







http://alejandro-anv.blogspot.com.es/2012/12/hackeando-termometro-inalambrico.html



Code:
#include <PinChangeInt.h>
#include <ByteBuffer.h>


#define DATA 8
#define BUFLEN 20
#define MAXBITS 32


ByteBuffer buffer;

unsigned long paquete=0L;
byte bits_paquete=0;


//////////////////////////////////////////////////

void cambio() {
unsigned long m;
static unsigned long dur_low;
static unsigned long dur_high;
static bool recibiendo=0;
static unsigned long lmicros=0;
static unsigned long hmicros=0;

m=micros();
if (digitalRead(DATA)==HIGH){  //flanco de subida
    hmicros=m; 
 
    dur_low=m-lmicros;

    //si el ultimo pulso alto duro 1ms, es un separador de pulsos y hay que procesar este dato
    if (recibiendo){
       if (dur_low<1800L) return; //tiene que tener por lo menos 1,8ms
       if (dur_low>8000L) { //si es un pulso de 10ms, es un fin de paquete
           digitalWrite(13,HIGH);
           procesar_paquete();
           return;
           }
       digitalWrite(13,LOW);           
       agregar_pulso(dur_low>3000L);  //si el pulso es de 5ms, es un 1, si es de 2 ms es un 0
       }
   
   
    return;
    }   
//flanco de bajada

lmicros=m;
dur_high=m-hmicros;
//si es un pulso de 0,5ms estamos recibiendo datos
if (dur_high>400L && dur_high<900L) {
    recibiendo=1;

    }
else {
    bits_paquete=0;
    recibiendo=0;
    paquete=0L;
    }

}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void agregar_pulso(bool valor){
paquete=(paquete<<1) | valor;
bits_paquete++;

}


////////////////////////////////////////////////////////////////////////////
void procesar_paquete(){
buffer.put(bits_paquete);
buffer.putLong(paquete);
paquete=0L;
bits_paquete=0;

}


////////////////////////////////////////////////////////////////////////////
void setup() {
  buffer.init(20);
  buffer.clear();
 
  pinMode(DATA, INPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13,LOW);
  pinMode(12, OUTPUT);
  PCintPort::attachInterrupt(DATA, &cambio, CHANGE);
  Serial.begin(115200);
  Serial.println("---------------------------------------");
}

/////////////////////////////////////////////////////////////////////////////////////
void mostrar_dato(unsigned long p){
float temp;
bool bot;
byte canal=0;
byte a;
word b;
byte c;
Serial.print("datos:");
Serial.println(p,BIN);
/*
4 bits  ???? (va variando)

8 bits ? (fijo)

12 bits temperatura en celsius
2 bits canal
2 bits ?? (fijo)
*/


a=(p & 0b1110000000000000000000000000) >> 25;
b=(p & 0b0000111111110000000000000000) >> 16;
a=(p & 0b0000000000000000000000000011);

bot=(p & 0b0001000000000000000000000000 !=0);

temp=(0.0+((p & 0b0000000000001111111111110000) >> 4)) /10;
if (temp>204.8) temp-=409.6;

canal=(p & 0b0000000000000000000000001100) >> 2;

Serial.print("temp:");
Serial.println(temp);

Serial.print("boton:");
Serial.println(bot);

Serial.print("canal:");
Serial.println(canal);


Serial.print(a,BIN);
Serial.print(" ");
Serial.print(b,HEX);
Serial.print(" ");
Serial.println(c,BIN);


}



/////////////////////////////////////////////////////////////////////////////////////
unsigned long p;
unsigned long ant=0;
unsigned long rep=0;
unsigned long tiempo=0,m=0;
byte l;
byte estado=0;

void loop() {
 
if (buffer.getSize()>4){

   l=buffer.get(); 
   p=buffer.getLong();
   
   if (l==28){
       tiempo=millis()-m;
       m=millis();
       if (estado==0){ //esperando repeticiones
          if(ant==p) rep++;
          else rep=0;
         
          if (rep>4) {
             estado=1;

             mostrar_dato(p);
             }
          }
       else if(estado==1){ //al menos 4 repeticiones
          if(ant!=p || tiempo>1000) estado=0;//ya no se repite
          }
       ant=p;

       }  //l==28
   }//buffer con datos

}
19  Using Arduino / Installation & Troubleshooting / Re: Problems with 1.x (at least under Linux) on: August 17, 2012, 08:11:55 am
This does not work for you on v1.0.1?
Code:
void setup() {
  Serial.begin(9600);
  Serial.println("setup complete");
}

void loop() {
  Serial.println("tick");
  delay(1000);
}



I just installed 1.0.1, uploaded this and worked ok. Then uploaded ascii table and worked, and uploaded the program that uses the display and it works.

Really I don't know what happened. Sorry for boring with this.
20  Using Arduino / Installation & Troubleshooting / Re: Problems with 1.x (at least under Linux) on: August 17, 2012, 07:56:33 am
IDE v1.0.1 is working great for me in Ubuntu v11.10 and v12.04 with a Mega 2560. I noticed there have been a few format and data type changes when porting from v0022 to v1.0.1.
I understand there are some changes, but the samples should work!, and the serial port is basic.

What is "not working" about Serial.println()? Not compiling? Not running? Not printing anything on the serial output?

The problem compiles and uploads OK but I am not receiving anything thrugh the serial port (usb). The same program compiled with 0022 works ok.

My program started when I tried to get working this display: http://dx.com/p/jy-mcu-16x-digital-tube-yellow-led-module-104311?utm_rid=68099021&utm_source=affiliate with this library:http://code.google.com/p/tm1638-library/ that claims it is compatible with Arduino 1.0 since many versions.

When uploaded the small sample program included with the library I found random leds displayed, then I tried to debug the app inserting some Serial.println, but I received nothing in the serial monitor. Then I inserted a Serial.println at setup function and when it didn't work (sent nothing, no tx/rx leds blinking, etc.). Then I tried uploading the ascii table example of Arduino IDE and it sent nothing through serial port.

My next step was installing Arduino 0022 and all the programa (ascii table and display library worked well).

I must say that some months ago, I had similar problems with Arduino 1.0 and Arduino ISP (it only worked with Arduino 0022).
21  Using Arduino / Installation & Troubleshooting / Re: DIY Arduino problem on: August 17, 2012, 07:35:54 am
The minimum is just the cap for power supply ? Then how can I use the internal oscillator ? What setting should I change ?

For avoiding the crystal, you should program the atmega as 8Mhz internal oscilator. Select arduino pro mino 8Mhz in arduino IDE as target board in order to obtain the right times.
22  Using Arduino / Installation & Troubleshooting / [SOLVED] Problems with 1.x (at least under Linux) on: August 17, 2012, 07:25:38 am
I am having problems with binaries generated by arduino 1.x
The blink test works OK but some programs that worked in arduino 0.x does not work. The more serious problem is that Serial.println does not work in my arduino mega 1280.

I am using the same compiler for both verions of Arduino (0.22 and 1.0.1) (cross-avr-binutils-2.20-1, avrdude-5.11.1-1, cross-avr-gcc-c++-4.6.2-1, avr-gdb-7.1-3, cross-avr-gcc-4.6.2-1).

I understand there may be some differences between 0.x and 1.x and some programs may not work, the ascii chart sample should work!! There must be a problem in my system but if 0.22 works ok, what can be going wrong?

EDIT: The program compiles and uploads OK but nothing is sent to serial port and tx/rx leds does not blink.

23  Using Arduino / Programming Questions / Re: Changing clock speed on: January 28, 2012, 07:41:50 am
Be aware that the internal oscillator might not be accurate enough for the bootloader's serial communications to work correctly (or so I've heard)

If you are programming using ICSP this isn't an issue (although its a little complicated (and slow) to upload sketches via ICSP).

Up to now, the few uploads I made worked OK.
24  Using Arduino / Programming Questions / Changing clock speed on: January 28, 2012, 04:39:28 am
I am building a project whch does not need much speed or accurate. Then I decided to avoid the use of the crystal and program the atmega with 8Mhz internal oscilator.

In order to use the same program as with a normal arduino, I only programmed the fuses and bootloader as indicated in the arduino to breadboard tutorial, but added the board definition to the list of Arduino, in order to continue using the normal pin names.

My problem is that the compiler seems to asume the clock speed is 16Mhz because the times are double of the programmed. Un the data I added, I indicated "atmega328bb.build.f_cpu=8000000L".

¿Is there anything more that I need change or the libraries are made only for 16Mhz?



The section I added is this:

Code:
atmega328.name=Arduino ATmega328 8 MHz internal clock

atmega328.upload.protocol=arduino
atmega328.upload.maximum_size=30720
atmega328.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.bootloader.unlock_bits=0x3F

atmega328.bootloader.path=atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex

atmega328.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328.build.core=arduino
atmega328.build.variant=standard
25  Using Arduino / Programming Questions / Re: stk500_recv(): programmer is not responding when programming bootloader on: January 22, 2012, 02:02:17 pm
Are you using the ArduinoISP sketch with Arduino 1.0 by any chance? I recently chased down a problem I was having very similar to yours - avrdude "writing..." to about 96%, then failing. This thread has the details.

Try using a pre-1.0 Arduino IDE (0022 or 0023) to build and upload ArduinoISP. Alternately, the user Coding Badly is offering a patched version of ArduinoISP in that thread that should work with 1.0.

Yes!! I'm using 1.0!! I will try an older version and contacting Coding Badly. If I solve the problem I will post in this thread.
26  International / Español / Re: stk500_recv(): programmer is not responding on: January 22, 2012, 08:42:54 am
Hazlo con el IDE de arduino, te vas a Burn Bootloader -> Arduino as ISP

Fue lo primero que hice. Despues lo hice desde linea de comando para ver con más detalle el error que daba.
27  International / Español / Re: No puedo programar Atmega328 con ArduinoISP on: January 22, 2012, 07:19:48 am
Ya descubrí el problema. El cristal que estaba usando estaba fallado. Pero ahora tengo un problema diferente:


# /usr/lib/arduino/hardware/tools/avrdude -C/usr/lib/arduino/hardware/tools/avrdude.conf  -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex"
avrdude: writing flash (32670 bytes):

Writing | ###############################################    | 94% 0.01savrdude: stk500_recv(): programmer is not responding


He iniciado un nuevo hilo para preguntar sobre esto así no mezclamos las cosas.
28  International / Español / stk500_recv(): programmer is not responding on: January 22, 2012, 07:18:10 am
Estoy tratando de programar un nuevo chip atmega328 en una breadboard como se indica en http://arduino.cc/en/Tutorial/ArduinoToBreadboard

He probado hacerlo con y sin cristal (con la configuración correspondiente) y en ambos casos obtengo el mismo error:


# /usr/lib/arduino/hardware/tools/avrdude -C/usr/lib/arduino/hardware/tools/avrdude.conf  -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex"
avrdude: writing flash (32670 bytes):

Writing | ###############################################    | 94% 0.01savrdude: stk500_recv(): programmer is not responding

29  Using Arduino / Programming Questions / stk500_recv(): programmer is not responding when programming bootloader on: January 22, 2012, 07:14:16 am
I am trying to burn the arduino bootloader as described in http://arduino.cc/en/Tutorial/ArduinoToBreadboard

I've tried with crystal and with no crystal with the same result:


# /usr/lib/arduino/hardware/tools/avrdude -C/usr/lib/arduino/hardware/tools/avrdude.conf  -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex"
avrdude: writing flash (32670 bytes):

Writing | ###############################################    | 94% 0.01savrdude: stk500_recv(): programmer is not responding


Any ideas please?
30  Using Arduino / Programming Questions / Re: ArduinoISP on: January 22, 2012, 07:06:34 am
Semi solved the problem.

The problem was a bad crystal. The arduino ide programmed the fuses to use crystal oscilator, but the crystal was broken. I replaced it and it started detecting the chip, but the write process aborts. I tried also with a 8Mhz crystal-less setup with exactly the same result.

# /usr/lib/arduino/hardware/tools/avrdude -C/usr/lib/arduino/hardware/tools/avrdude.conf  -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/usr/lib/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex"
avrdude: writing flash (32670 bytes):

Writing | ###############################################    | 94% 0.01savrdude: stk500_recv(): programmer is not responding


I think it is better to start a new thread with this issue.
Pages: 1 [2] 3 4 5