Go Down

Topic: Include AVR files (avr/sleep.h) (Read 6920 times) previous topic - next topic

smajeed

I am currently using the Arduino Due, a Macbook pro, and have purchased a BLE shield from Red Bear labs (http://redbearlab.com/bleshield/)
I have installed their libraries, however I am having problems running their example projects. The Arduino IDE says that <avr/sleep.h> could not be found:


Code: [Select]
In file included from BLEControllerSketch.ino:16:0:
/Users/shazkam/Documents/Arduino/libraries/RBL_nRF8001/RBL_nRF8001.h:21:23: fatal error: avr/sleep.h: No such file or directory
#include <avr/sleep.h>
                      ^
compilation terminated.


However, the avr library and the sleep.h file are included with the arduino software as can be seen from my screen shot: http://i.imgur.com/tecWrNA.png

Most of the example code that I am trying to run can be found below (I could not put all of it as characters here are limited)

Code: [Select]

#include <Servo.h>
#include <SPI.h>
#include <boards.h>
#include <RBL_nRF8001.h>
#include <services.h>
#include "Boards.h"

#define PROTOCOL_MAJOR_VERSION   0 //
#define PROTOCOL_MINOR_VERSION   0 //
#define PROTOCOL_BUGFIX_VERSION  2 // bugfix

#define PIN_CAPABILITY_NONE      0x00
#define PIN_CAPABILITY_DIGITAL   0x01
#define PIN_CAPABILITY_ANALOG    0x02
#define PIN_CAPABILITY_PWM       0x04
#define PIN_CAPABILITY_SERVO     0x08
#define PIN_CAPABILITY_I2C       0x10

// pin modes
//#define INPUT                 0x00 // defined in wiring.h
//#define OUTPUT                0x01 // defined in wiring.h
#define ANALOG                  0x02 // analog pin in analogInput mode
#define PWM                     0x03 // digital pin in PWM output mode
#define SERVO                   0x04 // digital pin in Servo output mode

byte pin_mode[TOTAL_PINS];
byte pin_state[TOTAL_PINS];
byte pin_pwm[TOTAL_PINS];
byte pin_servo[TOTAL_PINS];

Servo servos[MAX_SERVOS];

void setup()
{
 Serial.begin(57600);
 Serial.println("BLE Arduino Slave");
 
 /* Default all to digital input */
 for (int pin = 0; pin < TOTAL_PINS; pin++)
 {
   // Set pin to input with internal pull up
   pinMode(pin, INPUT);
   digitalWrite(pin, HIGH);

   // Save pin mode and state
   pin_mode[pin] = INPUT;
   pin_state[pin] = LOW;
 }

 // Default pins set to 9 and 8 for REQN and RDYN
 // Set your REQN and RDYN here before ble_begin() if you need
 //ble_set_pins(3, 2);
 
 // Set your BLE Shield name here, max. length 10
 //ble_set_name("My Name");
 
 // Init. and start BLE library.
 ble_begin();
}

static byte buf_len = 0;

...

byte reportPinAnalogData()
{
 if (!ble_connected())
   return 0;
   
 static byte pin = 0;
 byte report = 0;
 
 if (!IS_PIN_DIGITAL(pin))
 {
   pin++;
   if (pin >= TOTAL_PINS)
     pin = 0;
   return 0;
 }
 
 if (pin_mode[pin] == ANALOG)
 {
   uint16_t value = analogRead(pin);
   byte value_lo = value;
   byte value_hi = value>>8;
   
   byte mode = pin_mode[pin];
   mode = (value_hi << 4) | mode;
   
   byte buf[] = {'G', pin, mode, value_lo};        
   ble_write_string(buf, 4);
 }
 
 pin++;
 if (pin >= TOTAL_PINS)
   pin = 0;
   
 return report;
}

...

byte queryDone = false;

void loop()
{
 while(ble_available())
 {
   byte cmd;
   cmd = ble_read();
   Serial.write(cmd);
   
   // Parse data here
   switch (cmd)
   {
     case 'V': // query protocol version
       {
         byte buf[] = {'V', 0x00, 0x00, 0x01};
         ble_write_string(buf, 4);
       }
       break;
     
     case 'C': // query board total pin count
       {
         byte buf[2];
         buf[0] = 'C';
         buf[1] = TOTAL_PINS;
         ble_write_string(buf, 2);
       }        
       break;
     
     case 'M': // query pin mode
       {  
         byte pin = ble_read();
         byte buf[] = {'M', pin, pin_mode[pin]}; // report pin mode
         ble_write_string(buf, 3);
       }  
       break;
     
     case 'S': // set pin mode
       {
         byte pin = ble_read();
         byte mode = ble_read();
         
         if (IS_PIN_SERVO(pin) && mode != SERVO && servos[PIN_TO_SERVO(pin)].attached())
           servos[PIN_TO_SERVO(pin)].detach();
 
         /* ToDo: check the mode is in its capability or not */
         /* assume always ok */
         if (mode != pin_mode[pin])
         {              
           pinMode(pin, mode);
           pin_mode[pin] = mode;
         
           if (mode == OUTPUT)
           {
             digitalWrite(pin, LOW);
             pin_state[pin] = LOW;
           }
           else if (mode == INPUT)
           {
             digitalWrite(pin, HIGH);
             pin_state[pin] = HIGH;
           }
           else if (mode == ANALOG)
           {
             if (IS_PIN_ANALOG(pin)) {
               if (IS_PIN_DIGITAL(pin)) {
                 pinMode(PIN_TO_DIGITAL(pin), LOW);
               }
             }
           }
           else if (mode == PWM)
           {
             if (IS_PIN_PWM(pin))
             {
               pinMode(PIN_TO_PWM(pin), OUTPUT);
               analogWrite(PIN_TO_PWM(pin), 0);
               pin_pwm[pin] = 0;
               pin_mode[pin] = PWM;
             }
           }
           else if (mode == SERVO)
           {
             if (IS_PIN_SERVO(pin))
             {
               pin_servo[pin] = 0;
               pin_mode[pin] = SERVO;
               if (!servos[PIN_TO_SERVO(pin)].attached())
                 servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
             }
           }
         }
           
 //          reportPinAnalogData(pin);
         if ( (mode == INPUT) || (mode == OUTPUT) )
           reportPinDigitalData(pin);
         else if (mode == PWM)
           reportPinPWMData(pin);
         else if (mode == SERVO)
           reportPinServoData(pin);
       }
       break;

...
     case 'A': // query all pin status
       for (int pin = 0; pin < TOTAL_PINS; pin++)
       {
         reportPinCapability(pin);
         if ( (pin_mode[pin] == INPUT) || (pin_mode[pin] == OUTPUT) )
           reportPinDigitalData(pin);
         else if (pin_mode[pin] == PWM)
           reportPinPWMData(pin);
         else if (pin_mode[pin] == SERVO)
           reportPinServoData(pin);  
       }
       
       queryDone = true;
       {
         uint8_t str[] = "ABC";
         sendCustomData(str, 3);
       }
     
       break;
         
     case 'P':
       {
         byte pin = ble_read();
         reportPinCapability(pin);
       }
       break;
       
     case 'Z':
       {
         byte len = ble_read();
         byte buf[len];
         for (int i=0;i<len;i++)
           buf[i] = ble_read();
         Serial.println("->");
         Serial.print("Received: ");
         Serial.print(len);
         Serial.println(" byte(s)");
         Serial.print(" Hex: ");
         for (int i=0;i<len;i++)
           Serial.print(buf[i], HEX);
         Serial.println();
       }
   }

   // send out any outstanding data
   ble_do_events();
   buf_len = 0;
   
   return; // only do this task in this loop
 }

 if (Serial.available())
 {
   byte d = 'Z';
   ble_write(d);

   delay(5);
   while(Serial.available())
   {
     d = Serial.read();
     ble_write(d);
   }
   
   ble_do_events();
   buf_len = 0;
   
   return;    
 }

 // No input data, no commands, process analog data
 if (!ble_connected())
   queryDone = false; // reset query state
   
 if (queryDone) // only report data after the query state
 {
   byte input_data_pending = reportDigitalInput();  
   if (input_data_pending)
   {
     ble_do_events();
     buf_len = 0;
     
     return; // only do this task in this loop
   }
 
   reportPinAnalogData();
   
   ble_do_events();
   buf_len = 0;
   
   return;  
 }
   
 ble_do_events();
 buf_len = 0;
}


The file that is throwing the error is:

Code: [Select]
#ifndef  _RBL_NRF8001_H
#define _RBL_NRF8001_H

#include <boards.h>
#include <lib_aci.h>
#include <aci_setup.h>
#include <SPI.h>

#include <avr/sleep.h>
#include <avr/interrupt.h>

/* Put the nRF8001 setup in the RAM of the nRF8001.*/
#include "RBL_services.h"
/* Include the services_lock.h to put the setup in the OTP memory of the nRF8001.
This would mean that the setup cannot be changed once put in.
However this removes the need to do the setup of the nRF8001 on every reset.*/

#if defined(BLEND_MICRO)
#define DEFAULT_REQN    6
#define DEFAULT_RDYN    7
#else
#define DEFAULT_REQN    9
#define DEFAULT_RDYN    8
#endif

void ble_begin();
void ble_set_name(char *name);
void ble_write(unsigned char data);
void ble_write_bytes(unsigned char *data, unsigned char len);
void ble_do_events();
int ble_read();
unsigned char ble_available();
unsigned char ble_connected(void);
void ble_set_pins(uint8_t reqn, uint8_t rdyn);
unsigned char ble_busy();

#endif


I cannot seem to enable the compiler to the include the sleep.h file which is inside the Arduino app. Any help on this would be greatly appreciated.

robtillaart

can you make a  minimal sketch that shows this problem?
- which IDE version?
- which Arduino? (uno/mega)
- which platform? (win/mac/linux)

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

smajeed

#2
Jul 13, 2014, 05:53 pm Last Edit: Jul 13, 2014, 06:09 pm by smajeed Reason: 1
Hey robtillaart,

I am currently using an Arduino Due and trying to load code on a Macbook pro. The Arduino IDE version 1.0.5 would not upload anything to my board (my previous post on that problem: http://forum.arduino.cc/index.php?topic=249162.0), so now I am using the 1.5.7 version with no issues. However, when I try to import avr/sleep.h in any program, the IDE has a compilation error saying that the file cannot be found.

A simple program displaying this would be including this file in the blink program:

Code: [Select]
#include <avr/sleep.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}


The error can be seen below:


Code: [Select]
Blink.ino:16:23: fatal error: avr/sleep.h: No such file or directory
compilation terminated.



This is a strange error as I am able to include the file #include <avr/interrupt.h> which is located in the same place

robtillaart


The problem seems to be that the Due is an ARM processor and it has no support for AVR (atmel) libraries .
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

smajeed

Do you know if there is anyway to make this file compatible with the Due? The avr/interrupt.h seems to work fine.

robtillaart

Sorry too little due experience, better ask in the due subsection?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

sj_arduino

Have you found solution to compiling avr/<file.h> with Arduino Due? Please post the solution if you have one.

fatal error: avr/sleep.h: No such file or directory

robtillaart

#7
Jan 14, 2015, 09:38 pm Last Edit: Jan 14, 2015, 09:39 pm by robtillaart
in the ARM folder  C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino 

there exist an avr subfulder in which interrupt.h exists but not sleep.h

there is C:\Program Files (x86)\Arduino\hardware\arduino\sam\system\libsam\include\timetick.h   

with   extern void Sleep( volatile uint32_t dwMs ) ;

might be what you are looking for...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up