ST / Mbed 2 deprecated SunTracker_BLE

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 X_NUCLEO_IHM01A1 X_NUCLEO_IKS01A1 mbed

Fork of SunTracker_BLE by ST Expansion SW Team

Overview

The SunTracker is a demo application running on ST Nucleo-F401RE stacking a set of ST X-NUCLEO expansion boards.
Main features provided are:

  • A solar panel follows the light source, orienting the panel in order to achieve the best panel efficiency.
  • Orientation is controlled thanks to a couple of VL6180X FlightSense light sensors mounted on a X-NUCLEO-6180XA1 expansion board and driven by X-NUCLEO-IHM01A1 controlled stepper motor acting as actuator to orientate the panel.
  • The system features a progressive control on the stepper motor in order to modulate the panel rotation speed according to the light angle.
  • The application is also able to control the panel productivity reading the panel voltage through an ADC and proving feedback on the local display.
  • A manual orientation is possible by using the accelerometer on a X-NUCLEO-IKS01A1 expansion board that, according on board tilt, controls the speed and the rotate direction.
  • A remote control is available using a X-NUCLEO-IDB04A1 or a X-NUCLEO-IDB05A1 Bluetooth Low Energy expansion board. Remote control software is here.

/media/uploads/fabiombed/suntracker_server-client.png

Working Status

  • SunTracker has 3 working status visible on FlightSense display and switchable by pressing the User Button:

Status 0 (Idle)

  • Motor: Free Turning
  • Display: Waiting for User Button

Status 1

  • Motor: Driven by Light
  • Display: Direction and Light Intensity = Direction and Motor Speed

Status 2

  • Motor: Driven by Light
  • Display: Solar Panel Efficiency

Status 3

  • Motor: Driven by Accelerometer
  • Display: Direction and Accelerometer Intensity

Server Startup

  • When you plug the power supply, the word ‘PUSH’ is shown on display.
  • You can manually rotate the structure to assign the ‘Zero Point’. Then press the User Button to launch the application.
  • The display will show this status, which means that the structure is oriented to maximize the efficiency of the solar panel.
  • If there is a light displacement, the structure will rotate, left or right, to follow the light source and on display is shown the direction and the speed.
  • You can press the User Button to show the panel efficiency with 4 digits that represent the range from 0v (0000) to 3,3v (3300).
  • Further pressing the User Button you will manual rotate the panel by tilt the Server or Client accelerometer depending by BLE connection.

Client Startup

  • The Client application can remotely control the User Button and the Accelerometer functions.
  • Power on the Client AFTER the Server, it will automatically search for the SunTracker and will establish a BLE connection.
  • The Green Led on Nucleo Client board will be powered on.

Rotation Features

  • It has been implemented a block of rotation to avoid cables twist.
  • The blocking point can be set in the firmware by changing a constant.
  • You can manually rotate the structure to assign the ‘Zero Point’ before press the User Button to launch the application.
  • The system features a progressive control on the stepper motor in order to modulate the rotation speed according to the light or accelerometer angle.

List of Components

SERVER SunTracker_BLE

  • Stepper Motor 400’’ (Part Number 5350401) - To orientate the Mechanical Structure.
  • Solar Panel 0.446w (Part Number 0194127) - To capture sunlight and generate electrical current.
  • Power Supply 12v (Part Number 7262993) - To provide power supply at the Stepper Motor.
  • Flat Cable 6 ways (Part Number 1807010) - To plug VL6180X-SATEL with X-NUCLEO-6180XA1 (60cm length each x2).
  • Cable Connector (Part Number 6737694) - To plug the Flat Cable (x4).
  • Power Connector (Part Number 0487842) - To provide Power Supply to X-NUCLEO-IHM01A1.

CLIENT SunTracker_BLE_Remote

MECHANICAL STRUCTURE

Find here the STL files to print with a 3D printer.

/media/uploads/fabiombed/assembly.png

/media/uploads/fabiombed/mechanical_structure_and_motor_legs.png

FLAT CABLE ASSEMBLY

/media/uploads/fabiombed/flat_cable.png

HARDWARE SETUP

Nucleo ADC + Solar Panel

Connect Solar Panel cables to Nucleo Morpho PC_3 (white) and Nucleo Morpho GND (black). Connect a capacitor 10uF between PC_3 and GND to stabilize its voltage value shown on display.

EasySpin (L6474) + BLE

Hardware conflict between EasySpin DIR1 and BLE Reset, both on same Arduino Pin PA_8. Disconnect PA_8 between EasySpin and Nucleo by fold EasySpin Pin. PB_2 has been configured as EasySpin DIR1 in the firmware . Connect Nucleo Morpho PB_2 to FlightSense Arduino PA_8 by a wire.

FlightSense Satellites

In case of instability with I2C due to long flat cables, solder 4 SMD capacitors 47pF on FlightSense board in parallel between R15, R16, R17, R18 and plug 2 capacitors 15pF between FlightSense Arduino PB_8 and PB_9 to GND pin to cut-off noises over 720 KHz.

Arduino & Morpho Pinout

/media/uploads/fabiombed/arduino_pinout.png /media/uploads/fabiombed/morpho_pinout.png

Committer:
fabiombed
Date:
Thu Mar 03 16:32:10 2016 +0000
Revision:
11:b5e23d64d366
Parent:
6:4cbf7303b496
Temporary issued fixed avoiding to use NC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabiombed 6:4cbf7303b496 1 /**
fabiombed 6:4cbf7303b496 2 ******************************************************************************
fabiombed 6:4cbf7303b496 3 * @file main.cpp
fabiombed 6:4cbf7303b496 4 * @author Fabio Brembilla
fabiombed 6:4cbf7303b496 5 * @version V2.0.0
fabiombed 6:4cbf7303b496 6 * @date January 22th, 2016
fabiombed 6:4cbf7303b496 7 * @brief SunTracker + RemoteControl Vertical Application
fabiombed 6:4cbf7303b496 8 * This application use IHM01A1, 6180XA1, IKS01A1, IDB0XA1 expansion boards
fabiombed 6:4cbf7303b496 9 ******************************************************************************
fabiombed 6:4cbf7303b496 10 * @attention
fabiombed 6:4cbf7303b496 11 *
fabiombed 6:4cbf7303b496 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
fabiombed 6:4cbf7303b496 13 *
fabiombed 6:4cbf7303b496 14 * Redistribution and use in source and binary forms, with or without modification,
fabiombed 6:4cbf7303b496 15 * are permitted provided that the following conditions are met:
fabiombed 6:4cbf7303b496 16 * 1. Redistributions of source code must retain the above copyright notice,
fabiombed 6:4cbf7303b496 17 * this list of conditions and the following disclaimer.
fabiombed 6:4cbf7303b496 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
fabiombed 6:4cbf7303b496 19 * this list of conditions and the following disclaimer in the documentation
fabiombed 6:4cbf7303b496 20 * and/or other materials provided with the distribution.
fabiombed 6:4cbf7303b496 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
fabiombed 6:4cbf7303b496 22 * may be used to endorse or promote products derived from this software
fabiombed 6:4cbf7303b496 23 * without specific prior written permission.
fabiombed 6:4cbf7303b496 24 *
fabiombed 6:4cbf7303b496 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fabiombed 6:4cbf7303b496 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fabiombed 6:4cbf7303b496 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
fabiombed 6:4cbf7303b496 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
fabiombed 6:4cbf7303b496 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
fabiombed 6:4cbf7303b496 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
fabiombed 6:4cbf7303b496 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
fabiombed 6:4cbf7303b496 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fabiombed 6:4cbf7303b496 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
fabiombed 6:4cbf7303b496 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
fabiombed 6:4cbf7303b496 35 *
fabiombed 6:4cbf7303b496 36 ******************************************************************************
fabiombed 6:4cbf7303b496 37 */
fabiombed 6:4cbf7303b496 38
fabiombed 6:4cbf7303b496 39 /* Includes ------------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 40
fabiombed 6:4cbf7303b496 41 /* mbed specific header files. */
fabiombed 6:4cbf7303b496 42 #include "mbed.h"
fabiombed 6:4cbf7303b496 43
fabiombed 6:4cbf7303b496 44 /* Helper header files. */
fabiombed 6:4cbf7303b496 45 #include "DevSPI.h"
fabiombed 6:4cbf7303b496 46 #include "DevI2C.h"
fabiombed 6:4cbf7303b496 47
fabiombed 6:4cbf7303b496 48 /* Component specific header files. */
fabiombed 6:4cbf7303b496 49 #include "l6474_class.h"
fabiombed 6:4cbf7303b496 50 #include "x_nucleo_6180xa1.h"
fabiombed 6:4cbf7303b496 51 #include "x_nucleo_iks01a1.h"
fabiombed 6:4cbf7303b496 52
fabiombed 6:4cbf7303b496 53 /* C header files. */
fabiombed 6:4cbf7303b496 54 #include <string.h>
fabiombed 6:4cbf7303b496 55 #include <stdlib.h>
fabiombed 6:4cbf7303b496 56 #include <stdio.h>
fabiombed 6:4cbf7303b496 57 #include <assert.h>
fabiombed 6:4cbf7303b496 58
fabiombed 6:4cbf7303b496 59 /* BlueTooth -----------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 60
fabiombed 6:4cbf7303b496 61 #include "debug.h" // Need for PRINTF
fabiombed 6:4cbf7303b496 62 #include "Utils.h" // Need for STORE_LE_16 and _32
fabiombed 6:4cbf7303b496 63
fabiombed 6:4cbf7303b496 64 typedef struct {
fabiombed 6:4cbf7303b496 65 int32_t AXIS_X;
fabiombed 6:4cbf7303b496 66 int32_t AXIS_Y;
fabiombed 6:4cbf7303b496 67 int32_t AXIS_Z;
fabiombed 6:4cbf7303b496 68 } AxesRaw_TypeDef;
fabiombed 6:4cbf7303b496 69
fabiombed 6:4cbf7303b496 70 typedef enum ConnectionStatus_t {
fabiombed 6:4cbf7303b496 71 DISCONNECTED =0,
fabiombed 6:4cbf7303b496 72 CONNECTED =1
fabiombed 6:4cbf7303b496 73 }cns_t;
fabiombed 6:4cbf7303b496 74
fabiombed 6:4cbf7303b496 75 const unsigned LENGTH_OF_LONG_UUID = 16;
fabiombed 6:4cbf7303b496 76 typedef uint16_t ShortUUIDBytes_t;
fabiombed 6:4cbf7303b496 77 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
fabiombed 6:4cbf7303b496 78
fabiombed 6:4cbf7303b496 79 #include "CustomControlService.h"
fabiombed 6:4cbf7303b496 80 #include "CustomSensorsService.h"
fabiombed 6:4cbf7303b496 81
fabiombed 6:4cbf7303b496 82 static BLE * p_BLEdev = NULL;
fabiombed 6:4cbf7303b496 83
fabiombed 6:4cbf7303b496 84 #define BLE_DEV_NAME "SunTrack"
fabiombed 6:4cbf7303b496 85 #define BLE_DEV_MAC 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF
fabiombed 6:4cbf7303b496 86 #define BLE_ADVERTISING_INTERVAL 1000
fabiombed 6:4cbf7303b496 87
fabiombed 6:4cbf7303b496 88 /* Definitions ---------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 89
fabiombed 6:4cbf7303b496 90 #define SET_ACC 400 // Set Motor Acceleration
fabiombed 6:4cbf7303b496 91 #define SET_DEC 400 // Set Motor Deceleration
fabiombed 6:4cbf7303b496 92 #define SET_MAX 200 // Set Motor MaxSpeed
fabiombed 6:4cbf7303b496 93 #define SET_MIN 100 // Set Motor MinSpeed
fabiombed 6:4cbf7303b496 94 #define STOP 1000 // Set Motor Stop Position
fabiombed 6:4cbf7303b496 95 #define TOLLERANCE 100 // Tollerance between Left and Right before Start Movement
fabiombed 6:4cbf7303b496 96 #define RANGE_1 200 // Range 1 for Motor Speed
fabiombed 6:4cbf7303b496 97 #define RANGE_2 500 // Range 2 for Motor Speed
fabiombed 6:4cbf7303b496 98
fabiombed 6:4cbf7303b496 99 /* Variables -----------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 100
fabiombed 6:4cbf7303b496 101 int16_t dir=0; // Motor Rotation Direction: 0 = Stop, 1 = Anticlockwise, 2 = Clockwise
fabiombed 6:4cbf7303b496 102 int16_t changedir=0; // Change Direction: 0 = No, 1 = Yes
fabiombed 6:4cbf7303b496 103 int16_t babybear=0; // Difference (in Lux) between Left and Right
fabiombed 6:4cbf7303b496 104 int acc_data[3]; // Difference of Accelerometer
fabiombed 6:4cbf7303b496 105 int16_t diff=0; // Abs of Babybear or Accelerometer difference
fabiombed 6:4cbf7303b496 106 int16_t left=0; // Left Command for Rotate Direction
fabiombed 6:4cbf7303b496 107 int16_t right=0; // Right Command for Rotate Direction
fabiombed 6:4cbf7303b496 108 int16_t start=0; // Waiting User Button Push
fabiombed 6:4cbf7303b496 109 int32_t pos=0; // Motor Position
fabiombed 6:4cbf7303b496 110 char DisplayStr[5]; // Status Display
fabiombed 6:4cbf7303b496 111 int16_t Display=0; // Shown on Display: 0 = Motor Speed, 1 = Solar Panel Value, 2 = Manual Control
fabiombed 6:4cbf7303b496 112 int16_t status, status_t, status_b, status_l, status_r; // Babybear Status
fabiombed 6:4cbf7303b496 113
fabiombed 6:4cbf7303b496 114 /* ---------------------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 115
fabiombed 6:4cbf7303b496 116
fabiombed 6:4cbf7303b496 117
fabiombed 6:4cbf7303b496 118 /* Bluetooth CallBack ---------------------------------------------------------*/
fabiombed 6:4cbf7303b496 119
fabiombed 6:4cbf7303b496 120 static void onUpdatesEnabledCallback(GattAttribute::Handle_t handle)
fabiombed 6:4cbf7303b496 121 {
fabiombed 6:4cbf7303b496 122
fabiombed 6:4cbf7303b496 123 }
fabiombed 6:4cbf7303b496 124
fabiombed 6:4cbf7303b496 125 static void onUpdatesDisabledCallback(Gap::Handle_t handle)
fabiombed 6:4cbf7303b496 126 {
fabiombed 6:4cbf7303b496 127
fabiombed 6:4cbf7303b496 128 }
fabiombed 6:4cbf7303b496 129
fabiombed 6:4cbf7303b496 130 static void onDataReadCallback(const GattReadCallbackParams *eventDataP)
fabiombed 6:4cbf7303b496 131 {
fabiombed 6:4cbf7303b496 132
fabiombed 6:4cbf7303b496 133 }
fabiombed 6:4cbf7303b496 134
fabiombed 6:4cbf7303b496 135 static void myonDataWriteCallback(const GattWriteCallbackParams *eventDataP)
fabiombed 6:4cbf7303b496 136 {
fabiombed 6:4cbf7303b496 137
fabiombed 6:4cbf7303b496 138 }
fabiombed 6:4cbf7303b496 139
fabiombed 6:4cbf7303b496 140 static void onConnectionCallback(const Gap::ConnectionCallbackParams_t * connectionParams)
fabiombed 6:4cbf7303b496 141 {
fabiombed 6:4cbf7303b496 142
fabiombed 6:4cbf7303b496 143 }
fabiombed 6:4cbf7303b496 144
fabiombed 6:4cbf7303b496 145 static void onDisconnectionCallback(const Gap::DisconnectionCallbackParams_t * disConnectionReason)
fabiombed 6:4cbf7303b496 146 {
fabiombed 6:4cbf7303b496 147
fabiombed 6:4cbf7303b496 148 }
fabiombed 6:4cbf7303b496 149
fabiombed 6:4cbf7303b496 150 /* Bluetooth Initialization ---------------------------------------------------*/
fabiombed 6:4cbf7303b496 151
fabiombed 6:4cbf7303b496 152 void BLE_Initialization(void)
fabiombed 6:4cbf7303b496 153 {
fabiombed 6:4cbf7303b496 154
fabiombed 6:4cbf7303b496 155 p_BLEdev = new BLE;
fabiombed 6:4cbf7303b496 156 if (!p_BLEdev) { printf("\r\nBLE Device creation failed\r\n"); }
fabiombed 6:4cbf7303b496 157
fabiombed 6:4cbf7303b496 158 const Gap::Address_t BLE_address_BE = {BLE_DEV_MAC};
fabiombed 6:4cbf7303b496 159 p_BLEdev->gap().setAddress(BLEProtocol::AddressType::PUBLIC, BLE_address_BE);
fabiombed 6:4cbf7303b496 160 printf("Line: %d \r\n", __LINE__);
fabiombed 6:4cbf7303b496 161 p_BLEdev->init();
fabiombed 6:4cbf7303b496 162 printf("Line: %d \r\n", __LINE__);
fabiombed 6:4cbf7303b496 163
fabiombed 6:4cbf7303b496 164 // Set BLE CallBack Functions
fabiombed 6:4cbf7303b496 165 p_BLEdev->gattServer().onUpdatesEnabled(onUpdatesEnabledCallback);
fabiombed 6:4cbf7303b496 166 p_BLEdev->gattServer().onUpdatesDisabled(onUpdatesDisabledCallback);
fabiombed 6:4cbf7303b496 167 p_BLEdev->gattServer().onDataRead(onDataReadCallback);
fabiombed 6:4cbf7303b496 168 p_BLEdev->gattServer().onDataWritten(myonDataWriteCallback);
fabiombed 6:4cbf7303b496 169 p_BLEdev->gap().onConnection(onConnectionCallback);
fabiombed 6:4cbf7303b496 170 p_BLEdev->gap().onDisconnection(onDisconnectionCallback);
fabiombed 6:4cbf7303b496 171 //p_BLEdev->gattServer().onConfirmationReceived(onConfirmationReceivedCallback);
fabiombed 6:4cbf7303b496 172 //p_BLEdev->gattServer().onDataSent(onDataSentCallback);
fabiombed 6:4cbf7303b496 173 //p_BLEdev->gap().onTimeout(onTimeoutCallback);
fabiombed 6:4cbf7303b496 174
fabiombed 6:4cbf7303b496 175 }
fabiombed 6:4cbf7303b496 176
fabiombed 6:4cbf7303b496 177 /* Main ----------------------------------------------------------------------*/
fabiombed 6:4cbf7303b496 178
fabiombed 6:4cbf7303b496 179 int main()
fabiombed 6:4cbf7303b496 180 {
fabiombed 6:4cbf7303b496 181
fabiombed 6:4cbf7303b496 182 //Initialization();
fabiombed 6:4cbf7303b496 183 printf("Line: %d \r\n", __LINE__);
fabiombed 6:4cbf7303b496 184 BLE_Initialization();
fabiombed 6:4cbf7303b496 185 printf("Line: %d \r\n", __LINE__);
fabiombed 6:4cbf7303b496 186
fabiombed 6:4cbf7303b496 187 /* Setup advertising. */
fabiombed 6:4cbf7303b496 188 const static char DEVICE_NAME[] = BLE_DEV_NAME;
fabiombed 6:4cbf7303b496 189 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
fabiombed 6:4cbf7303b496 190 #ifdef USE_SENSOR_FUSION_LIB
fabiombed 6:4cbf7303b496 191 uint8_t dat[]= {0x01,0x80,0x00,0xFC,0x01,0x80};
fabiombed 6:4cbf7303b496 192 #else
fabiombed 6:4cbf7303b496 193 uint8_t dat[]= {0x01,0x80,0x00,0xFC,0x00,0x00};
fabiombed 6:4cbf7303b496 194 #endif
fabiombed 6:4cbf7303b496 195 p_BLEdev->gap().accumulateScanResponse(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,dat,6);
fabiombed 6:4cbf7303b496 196 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::UNKNOWN);
fabiombed 6:4cbf7303b496 197 p_BLEdev->gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
fabiombed 6:4cbf7303b496 198 p_BLEdev->gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
fabiombed 6:4cbf7303b496 199 p_BLEdev->gap().setAdvertisingInterval(BLE_ADVERTISING_INTERVAL);
fabiombed 6:4cbf7303b496 200 p_BLEdev->gap().startAdvertising();
fabiombed 6:4cbf7303b496 201
fabiombed 6:4cbf7303b496 202 /* Printing to the console. */
fabiombed 6:4cbf7303b496 203 printf("SunTracker by Fabio Brembilla\r\n\n");
fabiombed 6:4cbf7303b496 204
fabiombed 6:4cbf7303b496 205 /* Main Loop. */
fabiombed 6:4cbf7303b496 206 while(true) {
fabiombed 6:4cbf7303b496 207
fabiombed 6:4cbf7303b496 208
fabiombed 6:4cbf7303b496 209
fabiombed 6:4cbf7303b496 210
fabiombed 6:4cbf7303b496 211 p_BLEdev->waitForEvent();
fabiombed 6:4cbf7303b496 212 }
fabiombed 6:4cbf7303b496 213
fabiombed 6:4cbf7303b496 214
fabiombed 6:4cbf7303b496 215 }