Forum >Replies by jacob.kamminga
userhead jacob.kamminga
Replies (5)
  • You Reply: Last are code snippets from the adapted ESP8266 Library

    Created a methode nop.

    void Esp8266::nop (unsigned int timeout)
    {
    for (int i ; i < timeout ; i++);
    }

    here the adapted code for checkMode:

    char Esp8266::checkMode() {
    //Serial.println ("\n_cM1 start");
    clearBuf();
    //Serial.println ("_cM2 buf cleared");
    write ("AT+CWMODE?");
    //delay(200); //this causes a freeze
    nop (2000); // This delays and doesn't cause a freeze
    //Serial.println ("_cM3 AT mode requested");
    String str = readData();
    //Serial.println("_cM4 String is: " + str);
    if (str.indexOf('1') > 0 )
    return '1';
    else if (str.indexOf('2') > 0)
    return '2';
    else if (str.indexOf('3') > 0)
    return '3';
    else
    return '0';
    }

    And here the adapted code for setMux:

    bool Esp8266::setMux (int flag) {
    const int timeout = 1000;

    //Serial.println ("\n_setMux1 start");
    String str;
    clearBuf();
    //Serial.println ("_setMux2 After clearbuf");
    write ("AT+CIPMUX="+String(flag));
    //Serial.println ("_setMux3 After write");

    for (int i ; i < timeout ; i++);

    //delay (100);

    //Serial.println ("_setMux4 Before ReadData");
    str = readData ();
    //Serial.println ("_setMux5 String is: " + str);


    if (str.indexOf("OK")>0 || str.indexOf("link is builded")>0)
    return true;
    else
    return false;
    }
  • You Reply: This the last one Had both LED's blinking on both MO and UNO.

    //
    // BlinkCrossTest.cpp(ino)
    //

    #include <Arduino.h>


    #define PERIOD 1000

    #define BLINKER 11
    #define ANOTHERLED 10

    uint8_t __tickerPin = BLINKER;
    unsigned int __deltaT = PERIOD;
    bool __light = LOW;
    unsigned long __prevHBT = 0; // Previous Heart Beat time
    unsigned int __cumN = 0; // number of samples in cumLT



    void heartBeat ()
    {
    unsigned long currentT = millis(); // Take time time sample
    if ( currentT - __prevHBT >= __deltaT) // Delta time passed?
    {
    __prevHBT = currentT; // Reset previous measure
    __light = (__light) ? LOW : HIGH; // toggle light
    digitalWrite (__tickerPin, __light); // and display
    }
    }


    void setup() {
    pinMode (BLINKER, OUTPUT);
    pinMode (ANOTHERLED, OUTPUT);
    }

    void loop() {

    heartBeat ();

    digitalWrite (ANOTHERLED, HIGH);
    delay (400);
    digitalWrite (ANOTHERLED, LOW);
    delay (400);
    }

    //---[ end of file ]---
  • You Reply: This one is with Class copied in the source file.
    M0 didn't work on heartbeat LED did on the another LED.
    UNO both LEDS blink.

    //
    // BlinkCrossTestM0_class.cpp(ino)
    //

    #include <Arduino.h>

    #define PERIOD 1000 // heartBeat interval in milliseconds is 1 second

    #define BLINKER 11
    #define ANOTHERLED 10


    uint8_t __tickerPin;
    bool __light = LOW;
    unsigned long __prevHBT = 0; // Previous Heart Beat time
    unsigned int __cumLT = 0; // Cumulative Loop time
    unsigned int __cumN = 0; // number of samples in cumLT


    class Utils
    {
    public:
    Utils (uint8_t _pin);
    Utils (uint8_t _pin, unsigned int _deltaT);
    void heartBeat ();

    private:
    unsigned int __deltaT = 1000; // Time past before we change, default = 1000 1 sec.
    };
    //---[ End class Utils ]---

    Utils util (BLINKER, PERIOD);

    void setup() {
    // nop
    pinMode (ANOTHERLED, OUTPUT);
    }

    void loop() {
    delay (10); // Delay 10 to not have heartBeat executed constantly.
    util.heartBeat ();
    digitalWrite (ANOTHERLED, HIGH);
    delay (400);
    digitalWrite (ANOTHERLED, LOW);
    delay (400);
    }



    Utils::Utils (uint8_t _pin)
    {
    __tickerPin = _pin;
    pinMode (__tickerPin, OUTPUT); // Initialise the Heartbeat.
    }
    //===[ end Utils ]===

    Utils::Utils (uint8_t _pin, unsigned int _deltaT)
    {
    __tickerPin = _pin;
    pinMode (__tickerPin, OUTPUT); // Initialise the Heartbeat.
    __deltaT = _deltaT; // Set the Delta time measure
    }
    //===[ end Utils ]===


    void Utils::heartBeat ()
    {
    unsigned long currentT = millis(); // Take time time sample
    if ( currentT - __prevHBT >= __deltaT) // Delta time passed?
    {
    __prevHBT = currentT; // Reset previous measure
    __light = (__light) ? LOW : HIGH; // toggle light
    digitalWrite (__tickerPin, __light); // and display
    }
    }
    //---[ end of file ]---
  • You Reply: First attempt with blinking led and Library!
    On the MO the ANOTHER LED was blinking the heartbeat LED did NOT
    On the UNO both LEDs were blinking.

    The Main File.
    //
    // BlinkCrossTestM0.cpp(ino)
    //
    #include <Arduino.h>
    #include "heartbeat.h"

    #define PERIOD 1000 // heartBeat interval in milliseconds is 1 second

    #define BLINKER 11
    #define ANOTHERLED 10

    Utils util (BLINKER, PERIOD);

    void setup() {
    pinMode (ANOTHERLED, OUTPUT);
    }

    void loop() {
    delay (10); // Delay 10 to not have heartBeat executed constantly.
    util.heartBeat ();
    digitalWrite (ANOTHERLED, HIGH);
    delay (400);
    digitalWrite (ANOTHERLED, LOW);
    delay (400);


    }

    //---[ end of file ]---

    The header file

    /*
    * heartbeat.h
    */
    #ifndef UTILS_LIB_H_
    #define UTILS_LIB_H_
    #include <Arduino.h>

    class Utils
    {
    public:
    Utils (uint8_t _pin);
    Utils (uint8_t _pin, unsigned int _deltaT);
    void heartBeat ();

    private:
    unsigned int __deltaT = 1000; // Time past before we change, default = 1000 1 sec.
    };
    //---[ End class Utils ]---

    #endif /* UTILS_LIB_H_ */


    The cpp file

    /*
    * heartbeat.cpp
    *
    */

    #include "heartbeat.h"

    uint8_t __tickerPin;
    bool __light = LOW;
    unsigned long __prevHBT = 0; // Previous Heart Beat time
    unsigned int __cumLT = 0; // Cumulative Loop time
    unsigned int __cumN = 0; // number of samples in cumLT

    Utils::Utils (uint8_t _pin)
    {
    __tickerPin = _pin;
    pinMode (__tickerPin, OUTPUT); // Initialise the Heartbeat.
    }
    //===[ end Utils ]===

    Utils::Utils (uint8_t _pin, unsigned int _deltaT)
    {
    __tickerPin = _pin;
    pinMode (__tickerPin, OUTPUT); // Initialise the Heartbeat.
    __deltaT = _deltaT; // Set the Delta time measure
    }
    //===[ end Utils ]===

    void Utils::heartBeat ()
    {
    unsigned long currentT = millis(); // Take time time sample
    if ( currentT - __prevHBT >= __deltaT) // Delta time passed?
    {
    __prevHBT = currentT; // Reset previous measure
    __light = (__light) ? LOW : HIGH; // toggle light
    digitalWrite (__tickerPin, __light); // and display
    }
    }

    //===[ end of file: heartbeat.cpp ]===
  • You Reply: Hi What is the resolution for this problem.

    I have the same issue.
    Led 13 blinks fine when using Arduino IDE and sending a Sketch to the Edison Romeo Board
    But doesn't work when using the IOT Hello blink C++ example from Eclipse.
    That example does work when I send it to the Intel Edison Arduino board.
    Both Boards use the same poky Image: Linux romson 3.10.17-poky-edison+ #1 SMP PREEMPT Fri Jun 19 12:06:40 CEST 2015 i686 GNU/Linux

    So what is the difference?

    Thanks and regards,
    Jacob




    Example from EclipsIoT:
    Code: Select all
    * Author: Jessica Gomez <[email protected]>
     * Copyright (c) 2015 Intel Corporation.
     *
     * Permission is hereby granted, free of charge, to any person obtaining
     * a copy of this software and associated documentation files (the
     * "Software"), to deal in the Software without restriction, including
     * without limitation the rights to use, copy, modify, merge, publish,
     * distribute, sublicense, and/or sell copies of the Software, and to
     * permit persons to whom the Software is furnished to do so, subject to
     * the following conditions:
     *
     * The above copyright notice and this permission notice shall be
     * included in all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     * MERCHANTABILITY, dfrobot FOR A PARTICULAR PURPOSE AND
     * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     */

    /**
     * @file
     * @ingroup basic
     * @brief On board LED blink C++
     *
     * Blink the on board LED by writing a digital value to an output pin
     * using the IO mraa library.
     *
     * @date 29/09/2015
     */

    #include "mraa.hpp"

    #include <iostream>
    #include <unistd.h>

    /*
     * On board LED blink C++ example
     *
     * Demonstrate how to blink the on board LED, writing a digital value to an
     * output pin using the MRAA library.
     * No external hardware is needed.
     *
     * - digital out: on board LED
     *
     * Additional linker flags: none
     */

    int main()
    {
       // select onboard LED pin based on the platform type
       // create a GPIO object from MRAA using it
       mraa::Platform platform = mraa::getPlatformType();
       mraa::Gpio* d_pin = NULL;
       switch (platform) {
          case mraa::INTEL_GALILEO_GEN1:
             d_pin = new mraa::Gpio(3, true, true);
             break;
          case mraa::INTEL_GALILEO_GEN2:
             d_pin = new mraa::Gpio(13, true, false);
             break;
          case mraa::INTEL_EDISON_FAB_C:
             d_pin = new mraa::Gpio(13, true, false);
             break;
          default:
             std::cerr << "Unsupported platform, exiting" << std::endl;
             return mraa::ERROR_INVALID_PLATFORM;
       }
       if (d_pin == NULL) {
          std::cerr << "Can't create mraa::Gpio object, exiting" << std::endl;
          return mraa::ERROR_UNSPECIFIED;
       }

       // set the pin as output
       if (d_pin->dir(mraa::DIR_OUT) != mraa::SUCCESS) {
          std::cerr << "Can't set digital pin as output, exiting" << std::endl;
          return MRAA_ERROR_UNSPECIFIED;
       }

       // loop forever toggling the on board LED every second
       for (;;) {
          d_pin->write(1);
          sleep(1);
          d_pin->write(0);
          sleep(1);
       }

       return mraa::SUCCESS;
    }