Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cores/arduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
return ;
}

if ( (ulPin == 43) && (ulMode == INPUT) )
{
nrf_delay_ms(15);
TwoWire_begin();
TwoWire_beginTransmission(0x48);
TwoWire_write(BAT_VOLT_IN);
TwoWire_endTransmission();
return ;
}

if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
{
return ;
Expand Down
64 changes: 64 additions & 0 deletions libraries/BAT/bat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
****************************************************************************
* Copyright (c) 2017 Arduino srl. All right reserved.
*
* File : bat.cpp
* Date : 2017/04/10
* Revision : 0.0.1 $
* Author: jeff[at]arduino[dot]org
*
****************************************************************************

This library 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 2.1 of the License, or (at your option) any later version.

This library 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 this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "bat.h"

bat::bat(void) {

}

double bat::analogRead(void) {
double voltage;
uint32_t code=0;

nrf_delay_ms(150);

int i;
for (i=0;i<4;i++) {
recBuffer[i] = 0;
}

Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xED);
Wire.endTransmission();
nrf_delay_ms(15);
Wire.requestFrom(0x48,4, true);
recBuffer[0] = Wire.read();

for (i=1;i<4;i++) {
recBuffer[i] = Wire.read();
}

code = (recBuffer[0] << 24);
code |= (recBuffer[1] << 16);
code |= (recBuffer[2] << 8);
code |= recBuffer[3];

voltage = (6.665 * code) / 4096;

return voltage;
}
49 changes: 49 additions & 0 deletions libraries/BAT/bat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
****************************************************************************
* Copyright (c) 2017 Arduino srl. All right reserved.
*
* File : bat.h
* Date : 2017/04/10
* Revision : 0.0.1 $
* Author: jeff[at]arduino[dot]org
*
****************************************************************************

This library 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 2.1 of the License, or (at your option) any later version.

This library 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 this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef __BAT_H__
#define __BAT_H__

#include <Wire.h>
#include <stdint.h>
#include "Arduino.h"

extern "C" {
#include "nrf_delay.h"
}

#define REC_BUF_LENGTH 4

class bat {
public:
bat(void);
double analogRead(void);
private:
uint8_t recBuffer[REC_BUF_LENGTH];

};

#endif __BAT_H___
59 changes: 59 additions & 0 deletions libraries/BAT/examples/BatteryVoltageValue/BatteryVoltageValue.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
BatteryVoltageValue.ino
Written by Jeff Wu (jeff@arduino.org)
This example for the Arduino Primo board shows how to use
bat library.

This example allows you to get Battery Voltage Value of Primo
board, disabling STM32 enter to standby mode to avoid Primo board
enter to standby mode when Primo board is powered only by battery.
Primo board is able to send voltage value over serial port or BLE serial,
Create UART service compatible with Nordic's *nRF Toolbox* and Adafruit's
*Bluefruit LE* iOS/Android apps. You can also use another board with
serial_client example in File->Examples->BLE->Central menu to set up
a BLE serial connection between two different boards.
This example code is in the public domain.
*/

#include <BLEPeripheral.h>
#include <BLESerial.h>
#include <Wire.h>
#include <stm32pwr.h>
#include <bat.h>


// create ble serial instance
BLESerial bleSerial = BLESerial();

bat primo_bat;
double bat_voltage;

void setup() {
// custom services and characteristics can be added as well
bleSerial.setLocalName("Arduino Primo");
// start serial port at 115200 bps:
Serial.begin(115200);
// start BLE serial
bleSerial.begin();
// disable STM32 enter to standby mode
stm32pwr.disableStandbyMode() ;
// initialize the LED pin as an output
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
delay(300);
// turn LED on
digitalWrite(LED_BUILTIN, HIGH);
// get battery voltage value
bat_voltage = primo_bat.analogRead();
// print battery voltage vaule on serial port
Serial.print("Battery Voltage:" );
Serial.println(bat_voltage,3);
// print battery voltage vaule on BLE serial
bleSerial.print("Battery Voltage:" );
bleSerial.println(bat_voltage,3);
delay(300);
// turn LED off
digitalWrite(LED_BUILTIN, LOW);
}
19 changes: 19 additions & 0 deletions libraries/BAT/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#######################################
# Syntax Coloring Map bat
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

bat KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

analogRead KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
9 changes: 9 additions & 0 deletions libraries/BAT/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=BAT
version=0.0.1
author=Jeff Wu <jeff@arduino.org>
maintainer=Arduino <swdev@arduino.org>
sentence=bat
paragraph= This library is designed for using Primo board to get battery voltage value
category=Communication
url=http://www.arduino.org/learning/reference/bat
architectures=nrf52
35 changes: 18 additions & 17 deletions libraries/CIR/CIR.cpp → libraries/CIR/cir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
****************************************************************************
* Copyright (c) 2017 Arduino srl. All right reserved.
*
* File : CIR.cpp
* File : cir.cpp
* Date : 2017/03/10
* Revision : 0.0.1 $
* Author: jeff[at]arduino[dot]org
Expand All @@ -24,35 +24,35 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "CIR.h"
#include "cir.h"

CIR::CIR(void) {
cir::cir(void) {

}

void CIR::enableReceiver(void) {
delay(100);
void cir::enableReceiver(void) {
nrf_delay_ms(100);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA0);
Wire.endTransmission();
}

void CIR::disableReceiver(void) {
delay(15);
void cir::disableReceiver(void) {
nrf_delay_ms(15);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA1);
Wire.endTransmission();
}

bool CIR::getReceiverStatus(void) {
delay(150);
bool cir::getReceiverStatus(void) {
nrf_delay_ms(150);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA2);
Wire.endTransmission();
delay(15);
nrf_delay_ms(15);
Wire.requestFrom(0x48,4, true);
recBuffer[0] = Wire.read();

Expand All @@ -68,7 +68,7 @@ bool CIR::getReceiverStatus(void) {
return true;
}

uint32_t CIR::getDecode(void) {
uint32_t cir::digitalRead(void) {
uint32_t code=0;
code = (recBuffer[0] << 24);
code |= (recBuffer[1] << 16);
Expand All @@ -78,32 +78,33 @@ uint32_t CIR::getDecode(void) {
return code;
}

void CIR::enableTransmitter(void) {
delay(100);
void cir::enableTransmitter(void) {
nrf_delay_ms(100);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA3);
Wire.endTransmission();
nrf_delay_ms(1500);
}

void CIR::disableTransmitter(void) {
delay(15);
void cir::disableTransmitter(void) {
nrf_delay_ms(100);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA4);
Wire.endTransmission();

}

void CIR::sendEncode(uint32_t data) {
void cir::digitalWrite(uint32_t data) {

uint8_t transdata[4];
transdata[0] = (data >> 24);
transdata[1] = (data >> 16);
transdata[2] = (data >> 8);
transdata[3] = data;

delay(200);
nrf_delay_ms(200);
Wire.begin();
Wire.beginTransmission(0x48);
Wire.write(0xA5);
Expand Down
14 changes: 9 additions & 5 deletions libraries/CIR/CIR.h → libraries/CIR/cir.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
****************************************************************************
* Copyright (c) 2017 Arduino srl. All right reserved.
*
* File : CIR.h
* File : cir.h
* Date : 2017/03/10
* Revision : 0.0.1 $
* Author: jeff[at]arduino[dot]org
Expand Down Expand Up @@ -31,20 +31,24 @@
#include <stdint.h>
#include "Arduino.h"

extern "C" {
#include "nrf_delay.h"
}

#define SEND_BUF_LENGTH 256
#define REC_BUF_LENGTH 74

class CIR {
class cir {
public:
CIR(void);
cir(void);
void enableReceiver(void);
void disableReceiver(void);
bool getReceiverStatus(void);
uint32_t getDecode(void);
uint32_t digitalRead(void);

void enableTransmitter(void);
void disableTransmitter(void);
void sendEncode(uint32_t data);
void digitalWrite(uint32_t data);

uint16_t recData[34];
uint16_t leader_mark, leader_space, mark_max, mark_min, space_max, space_min;
Expand Down
Loading