I have been working on stm32l475vg board with mbed library and I want to control all 4 leds of the board. The problem is that mbed configure led3 and led4 to the same one. In the file PinNames.h the definitions are:
LED_RED = P0_25,
LED_GREEN = P0_3,
LED_BLUE = P1_1,
// mbed original LED naming
LED1 = LED_RED,
LED2 = LED_GREEN,
LED3 = LED_BLUE,
LED4 = LED_BLUE,
Does anyone know how I can control each of them separately?
As #KentaroOkuda said both of the leds are connected to PC_9 so it is not possible to control them individually
Related
For a work-related project, I developed a program using the ESP32 DevKitC V2 to scan for smart-beacons with specific MAC-Addresses. Everything was working fine until I decided to buy some DevKit V4. On the DevKit V4, it still scans some BLE Advertising signals but somehow not anymore the ones from the smart-beacons I need to track. The smart-beacons are the Smart Beacon Go Mini from blukii. The smart-beacons only act as BLE advertisers and advertise every second. I'm not trying to connect to them.
My questions are:
Do the DevKit V4 have different BLE capabilities than the V2? (couldn't find anything googling)
Any idea to solve this problem?
I develop using Platformio on VSCode.
platform.ini:
[env:esp32dev]
framework = arduino
platform = espressif32
board = az-delivery-devkit-v4
board_build.partitions = huge_app.csv
monitor_speed = 115200
lib_deps =
h2zero/NimBLE-Arduino#^1.4.0
main.cpp:
#include <Arduino.h>
#include "NimBLEDevice.h"
const int NUMBER_SCAN = 40; // number of scans to perform
const int SCAN_DURATION = 1.1; // duration of a scan in seconds
NimBLEScan *pBLEScan;
void collectAdvertisingPackets()
{
// scan NUMBER_SCAN times
for (int i = 0; i < NUMBER_SCAN; i++)
{
NimBLEScanResults result = pBLEScan->start(SCAN_DURATION);
// number of advertising devices found
int count = result.getCount();
Serial.printf("Total devices found: %d\n", count);
// for each device found
for (int j = 0; j < count; j++)
{
NimBLEAdvertisedDevice device = result.getDevice(j);
std::string macAddress = device.getAddress().toString();
Serial.println(macAddress.c_str());
}
pBLEScan->clearResults(); // delete results from BLEScan buffer to release memory
}
}
void setup()
{
// baudrate for serial communication
Serial.begin(115200);
// BLE scan
NimBLEDevice::init(""); // initialize the ESP32 microcontroller as a BLE device
pBLEScan = NimBLEDevice::getScan();
}
void loop()
{
collectAdvertisingPackets();
}
Any advice is greatly appreciated :)
What did I try: Wrote the code with another library (Neil Kolban BLE library), googling to find if this problem exists. BLE Advertising Signals from the blukii smart beacons are scanned by the ESP32 DevKitC V2 but not by the V4.
What I expected: BLE Advertising Signals from the Blukii Smart Beacons Go Mini to be scanned by the ESP32 DevKitC V4 (which works with the ESP32 DevKitC V2).
I made a nice code which generates fast PWM with 50% duty cycle and I can change the frequency with a potentiometer. It outputs straight and inverted channels with some dead time. I am using Arduino Micro aka ATmega32U4. The code is actually "Atmel" code. Code is working fine until I power Arduino Micro off and then on again.
I have programmed the code and registers so that the frequency is changeable from 10kHz to 100kHz. But after power on/off the frequency changes from 5kHz to 50kHz. After this has happened I have to program the board again using Arduino IDE, to make it work correctly. Again after power on/off it has changed. I am quite sure that one of the registers is overwritten by the "Arduino hardware abstraction layer" or however we should name it. I have not yet read out all the registers so I do not know which one is overwritten. I guess it's the prescaler.
How do I prevent this from happening? Should I write the register contents somewhere else? Or should I write it few times to be sure?
Why or how this is happening anyway?
Here's the code:
#define OSC1 5
#define OSC2 13
uint8_t read_reg1;
uint8_t read_reg2;
int pot, freq;
void setup() {
pinMode(OSC1, OUTPUT);
pinMode(OSC2, OUTPUT);
Serial.begin(9600);
cli(); // disable global interrupts
TCCR4A=0; // clear register
TCCR4B=0x06; // configure prescaler to 64 (CK = CLK / 64 = 1.5 MHz)
TCCR4C=0;
TCCR4D=0; // select Fast PWM operation (0 << WGM41)|(0 << WGM40)
PLLFRQ=(PLLFRQ&0xCF)|0x30; // select clock source and frequency
OCR4C=150; // select PWM frequency
OCR4A=150/2; // set duty cycle
DT4 = 0x55; // set dead times. DT = (1 / 48Mhz) * 0...15
// enable interrupt on timer4 overflow
TIMSK4|=(1 << TOIE4);
// This register write has to be after others. Otherwise the PWM generation will not work. I do not know why.
TCCR4A=0x42; // COM4A1..0 = 01, OC4A and !OC4A connected. PWM4A = 1 (activate channel A PWM output)
sei(); // enable global interrupts
}
void loop() {
//cli();
pot = analogRead(A0);
freq = map(pot, 0, 1023, 14, 166);
//sei();
/*
Serial.print("Pot value: ");
Serial.print(pot);
Serial.print("\tFreq value: ");
Serial.println(1500000/freq);
*/
}
ISR(TIMER4_OVF_vect){
OCR4C = freq;
OCR4A = freq / 2;
}
I am not sure exactly why you got different behavior right after programming, but the bootloader that the Arduino Micro uses (Caterina) does not perform a full reset after it runs, so changes that the bootloader made to the AVR's registers are often visible to the user's sketch.
I was able to fix the problem by removing the line that modifies PLLFRQ. Here is a simplified version of your code that always produces 3.31 kHz PWM:
void setup()
{
pinMode(5, OUTPUT);
pinMode(13, OUTPUT);
TCCR4A = 0;
TCCR4B = 0x06; // configure prescaler to 64 (CK = CLK / 64 = 1.5 MHz)
TCCR4C = 0;
TCCR4D = 0; // select Fast PWM operation (0 << WGM41)|(0 << WGM40)
OCR4C = 150; // select PWM frequency
OCR4A = 150 / 2; // set duty cycle
DT4 = 0x55; // set dead times. DT = (1 / 48Mhz) * 0...15
// This register write has to be after others.
// Otherwise the PWM generation will not work. I do not know why.
// COM4A1..0 = 01, OC4A and !OC4A connected.
// PWM4A = 1 (activate channel A PWM output)
TCCR4A = 0x42;
}
void loop()
{
}
It's not a great idea to mess with the PLL postscaler since it will probably affect every other Arduino library that uses timers, including the USB stack.
The Aim:
I am attempting to make a gimbal controller with an Arduino Mini for two brushless motors using two L6234 chips.
What I have done:
I have followed the following guide and it works perfectly:
http://www.berryjam.eu/2015/04/driving-bldc-gimbals-at-super-slow-speeds-with-arduino/
Circuit:
The circuit is built as the L6234 application note suggests, exactly like the guide above suggests.
Code:
The code they have there works perfect if I use the pins as defined in the code.
The problem:
Due to the fact that I want to run two motors from a single micro controller I have to change the pin outs of the arduino. When I try do this the motors are no longer driven correctly.
I have tried changing the pinout in the "void setPwmFrequency(int pin)" function too, with no success
Does anyone have any ideas how to fix this? Any help would be greatly appreciated.
Thank you
Misha
In the very unlikely event that anyone has the same issue, here is the answer;
The arduino has been setup on pins 3,5,6,7,9,10 and 11 to operate at 32kH. Thus, to run two motors using the code, as given in the BerryJam tutorial, one simply has to ensure that the "IN" pins are one of the ones mentioned above and code accordingly. See below for pinout clarification;
const int iEN11 = 4; // motor1 enable on phase 1
const int iEN12 = 4; // motor1 enable on phase 2
const int iEN13 = 4; // motor1 enable on phase 3
const int iIN11 = 3; // motor1 phase 1 signal
const int iIN12 = 5; // motor1 phase 2 signal
const int iIN13 = 6; // motor1 phase 3 signal
const int iEN21 = 7; // motor2 enable on phase 1
const int iEN22 = 7; // motor2 enable on phase 2
const int iEN23 = 7; // motor2 enable on phase 3
const int iIN21 = 9; // motor2 phase 1 signal
const int iIN22 = 10; // motor2 phase 2 signal
const int iIN23 = 11; // motor2 phase 3 signal
Hope it helps anyone.
I am trying to attach a servo on an Arduino (branded) Robot but not sure whhich pin to use for the bellow code.
Most people seem to recommend to use pin 9 and 10 to control the servo for arduino Unos.
However, I can't use Pin 9 because that is already used as the Slave Select pin for the LCD.
I have tried attaching it to pins TKD0-TKD3 by calling them pins 19-22 in myservo.attach(). The code runs but the servo doesn't rotate and only gets hot and/or twitches.
Could the problem be something other than incorrect pin connection?
Thanks,
-M
I have been referencing these for the Control board pin mapping:
http://arduino.cc/en/Main/Robot)
http://fabcirablog.weebly.com/blog/grappling-with-the-arduino-robot-control-board
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0;
void setup()
{
myservo.attach(19); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 60; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 60; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
}
You have this robot, right?
Arduino Robot
And you are using a classic servo (3 pins, yellow red and black cable)? If so.... Watch out. According to the schematic, the pinout of the connector on the board (e.g. TKD0) is
+5V
AD1
GND
While usually servos have
DATA
+5V
GND
So.. you have to make a short cable to invert the pins.
If that's not the problem.. Are you sure that 19 is the right number for the pin? I can't find references, but i suggest you to call it TKD0 (which is probably a macro defining the right pin), as arduino designers suggest you.
I hope your day is going well. I am programming a LPC1768 to send signals to at AD5791 in order to output a given frequency dependent on the output voltage of the AD5791. I have attached the circuit diagram. I have been able to seemingly read and write to the AD5791 from the LPC1768. However, when I connect the VCO to a signal analyzer I see no variation in the peak frequency when I "change" the voltage output of the AD5791. I have been programming using mbed. Below is the code I am currently using. Inputs would be greatly appreciated. I believe the issue may lie in how spi.write is implemented. The AD5791 requires 20-bit words and the LPC1768 can only send 16-bit words max. Also, there is the matter of endianness - but I believe I have solved that as I am reading out what I write to the AD5791 in the order expected.
#include "mbed.h"
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
int main()
{
spi.format(8,1);
spi.frequency(1000000);
cs=1;
while(1)
{
cs = 0;
spi.write(0x10);
spi.write(0xFF);
spi.write(0xFF);
cs = 1;
cs = 0;
int first = spi.write(0x90);
int second = spi.write(0x00);
int third = spi.write(0x00);
cs = 1;
printf("first register = 0x%X\n", first);
printf("second register = 0x%X\n", second);
printf("third register = 0x%X\n", third);
}
}`