5 Replies Latest reply on Oct 27, 2014 1:25 PM by DiegoV_Intel

    Danger Shield not working w Edison/Arduino

    raminf

      The 2nd edition of the Galileo shield report tests various popular Arduino shields running with the Edison (very handy, btw).

       

      One of the items it lists is the Sparkfun Danger shield (item #24). I realize the stock Danger code won't work with the Edison but there's a handy sketch listed that is supposed to work. It compiled fine and loaded. It starts by asking the user to press "Button 1 (D10)" to cycle through the tests. The output serial port prints out the startup strings so I know the sketch is running. But when I press the button nothing happens. So I over-rode the button press and tried all the individual tests (buttons, sliders, temperature sensor, light sensor, LEDs, buzzer, seven-segment display) and none of them worked.

       

      Has anyone tried to get the Danger shield working? I verified that the shield itself was working with an Arduino Uno so I know it's not the hardware.

       

      The goal is to send the data from the Danger shield across a pair of XBees from the Edison/Arduino to an Edison/mini-breakout board and have it display the IO values there. But starting with baby-steps...

       

      Any suggestions appreciated.

        • 1. Re: Danger Shield not working w Edison/Arduino
          DiegoV_Intel

          Hi raminf,

           

          I've just tested the Danger Shield with the Arduino Expansion Board for Edison and all the individual tests worked fine. Could you please attach the code you are using? I got the code from this document: Intel® Edison, Galileo & Galileo Gen 2 Shield Testing Report, pages 155 to 159.

           

          Regards,

          Diego.

          • 2. Re: Danger Shield not working w Edison/Arduino
            raminf

            Hi Diego,

             

            I transcribed the code from the same document. The forum text editor's not letting me attach a code file. I've included it below and also posted it up as a gist for easier loading: https://gist.github.com/raminf/1cdba049f8737235d6c5

             

            As I mentioned I tried the Danger board on an Uno and the stock Danger sketch worked fine. When I tried it on top of the Edison/Arduino board this code didn't work (this was with and without the XBee shield). I happen to have two Edison/Arduino boards so I tried them on both with the same result.

             

            Glad to hear it's working for you. I'm hoping it's an error in my transcription.

             

            Thanks--

             

             

            ------ start here ----


            //RM4GALILEO, #include <CapSense.h>

            /*

            * Danger Shield Example Sketch

            * Copyright (c) 2010 SparkFun Electronics.  All right reserved.

            * Written by Chris Taylor

            *

            * This code was written to demonstrate the Danger Shield from SparkFun Electronics

            *

            * This code will test all of the devices on the Danger Shield one at a time.

            * Press button 1 (D10) to cycle through the different tests. View their output on

            * a terminal running at 9600 baud.

            *

            * http://www.sparkfun.com

            */

            //#include "AdvancedIO.h"

            // Shift register bit values to display 0-9 on the seven-segment display

            const byte ledCharSet[10] = {

            B00111111,B00000110,B01011011,B01001111,B01100110,B01101101,B01111101,B00000111,B01111111,B01101111

            };

            // Global variables

            int val = 0;

            int state = 0;

            int x = 0;

            int i = 0;

            // Pin definitions

            #define SLIDER1  0

            #define SLIDER2  1

            #define SLIDER3  2

            #define KNOCK    5

            #define BUTTON1  10

            #define BUTTON2  11

            #define BUTTON3  12

            #define LED1  5

            #define LED2  6

            #define BUZZER   3

            #define TEMP  4

            #define LIGHT  3

            #define LATCH 7

            #define CLOCK 8

            #define DATA 4

            // State machine values

            #define SLIDER_TEST 1

            #define BUZZER_TEST 2

            #define CAPSENSE_TEST  3

            #define TEMP_TEST  4

            #define LIGHT_TEST 5

            #define BUTTON_TEST 6

            #define SEVENSEG_TEST 7

             

             

            //RM4GALILEO, CapSense cs_9_2 = CapSense(9,2); //Initializes CapSense pins

             

             

            void setup()

            {

              Serial.begin(9600);

              for(i=5; i>0; i--)

              {

              delay(1000*1);

              Serial.println(i);

              }

             

             

              //RM4GALILEO, cs_9_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // Calibrates CapSense pin timing

             

             

              pinMode(BUTTON1,INPUT);

              pinMode(BUTTON2,INPUT);

              pinMode(BUTTON3,INPUT);

             

              digitalWrite(BUTTON1,HIGH);

              digitalWrite(BUTTON2,HIGH);

              digitalWrite(BUTTON3,HIGH);

             

             

              pinMode(BUZZER, OUTPUT);

              pinMode(LED1, OUTPUT);

              pinMode(LED2, OUTPUT);

              digitalWrite(LED1,HIGH);

              digitalWrite(LED2,HIGH);

              pinMode(LATCH, OUTPUT);

              pinMode(CLOCK, OUTPUT);

              pinMode(DATA,OUTPUT);

             

             

              Serial.println("Danger Shield Component Test");

              Serial.println("Press Button 1 to begin.");

            }

             

             

            void loop()

            {

              if(!(digitalRead(BUTTON1))) // Change state

              {

                Serial.print("Got button1");

                delay(1); // Debounce

                state++;

                if(state > 7){

                  state = 1;

                }

                while(!(digitalRead(BUTTON1)));

              } 

             

             

            if(state == SLIDER_TEST) // Displays values of sliders

            {

              Serial.print("Sliders: ");

              val = analogRead(SLIDER1);

              Serial.print(" ");

              Serial.print(val);

              val = analogRead(SLIDER2);

              Serial.print("  ");

              Serial.print(val);

              val = analogRead(SLIDER3);

              Serial.print("  ");

              Serial.println(val);

              delay(300);

            }

             

             

            if(state == BUZZER_TEST) // Activates buzzer

            {

              for(int x = 0; x < 100; x++)

              {

                digitalWrite(BUZZER, HIGH);

                delay(2);

                digitalWrite(BUZZER, LOW);

                delay(2);

              }

            }

            if(state == CAPSENSE_TEST) // Tests CapSense pad

            {

              Serial.println("Skip-CapSense");

              //RM4GALILEO, long start = millis();

              //RM4GALILEO, long total1 =  cs_9_2.capSense(30);

              //RM4GALILEO, Serial.println(total1);

              delay(10);

            }

             

             

            if(state == TEMP_TEST) // Displays temp sensor values

            {

              val = analogRead(TEMP);

              Serial.print("Temp: ");

              Serial.println(val);

            }

             

             

            if(state == LIGHT_TEST) // Displays light sensor values

            {

              val = analogRead(LIGHT);

              Serial.print("Light: ");

              Serial.println(val);

            }

             

             

              if(state == BUTTON_TEST) // Toggles LED's depending on Buttons 2 and 3

              {

                Serial.println("Button 2 & 3 Test");

                if(digitalRead(BUTTON3))

                {

                  digitalWrite(LED1,HIGH);

              } else {

                  digitalWrite(LED1,LOW);

                }

                if(digitalRead(BUTTON2))

                {

                  digitalWrite(LED2,HIGH);

                }

              else {

                  digitalWrite(LED2,LOW);

                }

            }

             

             

              if(state == SEVENSEG_TEST) // Cycles through 0-9 on seven-segment

              {

                i = 0;

                Serial.println("Seven segment display test");

                while(1)

                {

                  digitalWrite(LATCH,LOW);

                  shiftOut(DATA,CLOCK,MSBFIRST,~(ledCharSet[i]));

                  digitalWrite(LATCH,HIGH);

                  i++;

                  if(i==10) {

                    i = 0;

                  }

                  delay(500);

                }

              }

            }

             

             

            /*

            ***********************************************************************

            * This function is part of wiringPi:

            *        https://projects.drogon.net/raspberry-pi/wiringpi/

            *

            *   wiringPi is free software: you can redistribute it and/or modify

            *   it under the terms of the GNU Lesser General Public License as published by

            *    the Free Software Foundation, either version 3 of the License, or

            *    (at your option) any later version.

            *

            *    wiringPi is distributed in the hope that it will be useful,

            *    but WITHOUT ANY WARRANTY; without even the implied warranty of

            *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

            *    GNU Lesser General Public License for more details.

            *

            *    You should have received a copy of the GNU Lesser General Public License

            *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.

            ***********************************************************************

            *   shiftOut:

            *      Shift data out to a clocked source

            */

             

            void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val)

            {

            int8_t i;

              if (order == MSBFIRST)

                for (i = 7 ; i >= 0 ; --i)

                {

                  digitalWrite (dPin, val & (1 << i));

                  digitalWrite (cPin, HIGH);

                  digitalWrite (cPin, LOW);

               }

               else

                for (i = 0 ; i < 8 ; ++i)

                {

                  digitalWrite (dPin, val & (1 << i));

                  digitalWrite (cPin, HIGH);

                  digitalWrite (cPin, LOW);

              }

            }

            • 3. Re: Danger Shield not working w Edison/Arduino
              DiegoV_Intel

              Hi raminf,

               

              I've just tried the code you linked and it worked without any problem. I'm using the Arduino Expansion Board for Edison. Why do you say the code is not working? When the sketch starts, you have to push the D10 button to switch into the different tests.

               

              Regards,

              Diego.

              • 4. Re: Danger Shield not working w Edison/Arduino
                raminf

                Hi Diego,

                 

                I'm using the Arduino Expansion board for Edison as well (in fact, two of them).

                 

                I load up the sketch through the Edison Arduino app, open the serial console and watch it count down and then it says it's waiting for me to press D10 (the button on the lower-left marked A2/S10 underneath the leftmost slider). I press it. Nothing happens. I press it many times, then all the other buttons. Still nothing. I load up the same board on a basic Arduino Uno and load the standard Danger sketch. Pressing D10 toggles through various test modes and they all work fine.

                 

                Looking at the code (and sprinkling around some Serial.println statements) it looks like the if(!(digitalRead(BUTTON1))) line never returns true so the body never get called.

                 

                FWIW, on the Edison /etc/version shows I'm running: "edison-weekly_build_68_2014-09-08_13-49-07"

                 

                The problem doesn't seem to be with the Danger board itself since it works fine on the Uno. Is there any sort of knob or switch or configuration setting I should be setting on the Edison/Arduino board?

                 

                Thanks--

                • 5. Re: Danger Shield not working w Edison/Arduino
                  DiegoV_Intel

                  Hi raminf,

                   

                  I'd suggest you to update you Arduino IDE. You can download it from here: Edison - Software Downloads. Also, did you try using another sketch like the blink example? Just to make sure the Arduino Expansion Board works fine.

                   

                  I edited an example from the Arduino IDE so you can try it with the Danger Shield. You have to use the sliders for A0 and A1 and see how the light in the LED D5 and D6 change. Try the code and post your results here.

                   

                   

                  const int analogInPin1 = A0;
                  const int analogOutPin1 = 5;
                  
                  const int analogInPin2 = A1;
                  const int analogOutPin2 = 6;
                  
                  int sensorValue1 = 0;
                  int outputValue1 = 0;   
                  
                  int sensorValue2 = 0; 
                  int outputValue2 = 0;   
                  
                  void setup() {
                  
                    Serial.begin(9600);
                  }
                  
                  void loop() {
                  
                    sensorValue1 = analogRead(analogInPin1);
                    sensorValue2 = analogRead(analogInPin2);
                  
                    outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
                    outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
                  
                    analogWrite(analogOutPin1, outputValue1);
                    analogWrite(analogOutPin2, outputValue2);
                  
                    Serial.print("slider1 = " );                   
                    Serial.print(sensorValue1);
                    Serial.print("\t output1 = ");   
                    Serial.print(outputValue1);
                    Serial.print("\t\t\t slider2 = " );                   
                    Serial.print(sensorValue2); 
                    Serial.print("\t output2 = ");   
                    Serial.println(outputValue2);
                  
                    delay(100);                 
                  }
                  

                   

                  Regards,

                  Diego.