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.
Related
Hey i got a bit problem with my Arduino and sensor
Here is what i tried ;
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <SoftwareSerial.h>
SoftwareSerial blue(0,1);
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
blue.begin(9600);
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);
pulseSensor.begin();
}
void loop() {
// put your main code here, to run repeatedly:
int myBPM = pulseSensor.getBeatsPerMinute();
if(myBPM>200){
myBPM-100;
}
if (pulseSensor.sawStartOfBeat()) {
Serial.println(myBPM);
blue.println(myBPM);
}
delay(10);
}
this code I got from the example library and modified it.
so i want to send data to my android using Bluetooth but this sensor kinda ticked me off because whenever i use it with my HC-06 Bluetooth module it suddenly got a hearth beat without i even touching it and it just sends so much data ignoring the delay I set.
I just need to slowly sending data just like a second but the data didn't show up
so anyone can help?
I read your code and I noticed this piece of code
if(myBPM > 200){ myBPM - 100; }
that is poorly written if (I understand correctly) you want to check the size of myBPM and if it is larger than 200 then it should be subtracted 100.
it should be:
myBPM = myBPM - 100; not myBPM - 100;
I hope my answer will help you. Have a nice day!
I am writing some Arduino code that is meant to control my 3D printed robot at a basic level. Everything works fine until the value that I analogWrite() to ledPin (pin 11 on the Nano) is no longer 0. The purpose of this bit of code is to fade some leds ON/OFF based on ambient lighting without using delay() function that pauses the program.
The code here determines whether the ambient light is below threshold, wheter 4 milliseconds have passed and whether the LEDs are at their target brightness yet, then increments/decrements the value to analogWrite() accordingly. It's when this value (lightVal) increases that the whole program freezes and remains in the state it was just before freezing. (The robot becomes unresponsive and serial data stops getting sent.) The moment I comment out the analogWrite(), the freeze does not occur.
timer = millis();
aLightVal = analogRead(LDR);
aLightVal = map(aLightVal, 0, 600, 0, 100);
//Check to see if the ambient light is below threshold
//If LED is not yet at target brightness, fade every 4 milliseconds
if (aLightVal < 40){
if (timer - currentTime > 4){
if (lightVal < 255){
lightVal++;
currentTime = timer;
}
}
}
if (aLightVal >= 40){
if (timer - currentTime > 4){
if (lightVal > 0){
lightVal--;
currentTime = timer;
}
}
}
analogWrite(ledPin, lightVal);
Serial.println(aLightVal);
I am using the Servo.h as well as the Ultrasonic.h libraries in the program if that helps?
I initialised the variables as follows:
const int LDR = A1;
const int ledPin = 11;
unsigned long timer = 0;
unsigned long currentTime = 0;
int aLightVal;
int lightVal = 0;
Any advice? Please let me know, I would really appreciate it!
I am trying to wire up a simple switch to an Arduino, as per the code below, for use in a model trainset.
When the buttonState is high, Serial.print(buttonState) shows 111111111, however, the problem I have is when buttonState should be low: Serial.print(buttonState) "flickers" between 0 and 1 like so: 000111100000101000111001.
Why is it doing this and how do I stop it? I assumed it was connections but when I simply use a wire between the 2 ports, plugging it in for on and unplugging for off I still get this issue.
int RED=6;
int YELLOW=5;
int GREEN=3;
int relaytrig = 10; // trigger on pin 10
int powertoswitch = 9; // powertoswitch
int buttonPin = 12; // switch the button comms with
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// inputs
// switch input
pinMode(buttonPin,INPUT);
// outputs
// powerforswitch
pinMode(powertoswitch,OUTPUT);
// track power
pinMode(relaytrig, OUTPUT);
//signal outputs
pinMode(RED,OUTPUT);
pinMode(YELLOW,OUTPUT);
pinMode(GREEN,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(powertoswitch,HIGH);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(relaytrig,LOW);
digitalWrite(GREEN,LOW);
digitalWrite(RED,HIGH);
digitalWrite(YELLOW,LOW);
Serial.print(buttonState);
} else if (buttonState == LOW) {
digitalWrite(relaytrig,HIGH);
digitalWrite(GREEN,HIGH);
digitalWrite(RED,LOW);
digitalWrite(YELLOW,LOW);
Serial.print(buttonState);
}
}
Unplugging it leaves the input pin floating, and noise etc. can make a floating input pin take any value.
Depending on your connection, you need a pull-down or a pull-up resistor on the pin to make it a 1 or a 0 when nothing is connected to it.
From the code, I assume the switching wire is between 5 V (or 3.3 V for some Arduinos) and an input pin. If I'm right, you need to put a, say, 10 kΩ resistor from that input pin to ground. This will keep it 0 when there is no wire connected.
BTW you are using an IO pin (9 aka powertoswitch) to provide the plus for the switch; there's no need and you shouldn't.
Connect one end of the switch to 5 V (or 3.3 V for some Arduinos), and the other end to the input pin. Connect the input pin with the resistor to ground (GND).
There's a picture here, but they use pin 2 as the input pin, and you use pin 12.
Also, your button or wire may need debouncing, but that is another matter.
I have this RFID reader "Rosslare AY-X12", and it's working with Wiegand 26bit. I have an arduino mini Pro and connected together it's working fine but it only reads the card one time and then I have nothing.
When I put on the card arduino reads that card but only one time during the card is near by the reader and it again reads that card when I put off the card and then I put on. But I want to read that card continuously, I mean when the card is near by the Reader still reading the card, every 1ms reads that card.
Do you have any idea how to do that ? Is there any RFID arduino library which can do that? I had got the Mifare and its can do that. But this 125Khz reader which can communicate over Wiegand can't do that or I don't know how to do that.
I'm using this library : https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino
My previous answer was deleted. I am going to make another attempt to answer the questions.
Do you have any idea how to do that ?
This cannot be done by Arduino because Arduino in your case is just reading the D0 and D1 pulses from your RFID reader. Since your RFID reader Rosslare AY-X12 does not send out continuous output of wiegand protocol, there is no way Arduino can read more than what was not sent to it.
The common RFID readers will not send continuous data of the same card because in the common use case (entry/exit/attendance), normally one tap is to check-in and another tap is to check-out. If the RFID reader sends continuous data of the same card, the main system receiving the multiple wiegand data will be confused and will not be able to determine if the user actually wish to check-in or check-out.
Is there any RFID arduino library which can do that?
No. There is no such RFID Arduino library. If the RFID reader is not sending out continuous data, there is no way the receiver (Arduino) can receive them.
Is there a way to achieve this?
Yes, there are some readers that has the option to turn on the continuous output of data, for example 714-52 Mifare® ID Reader with selectable outputs. In its specification :
Continuous output with tag in field or single transmission
With this reader configured to continuous output, you can then use Arduino and the monkeyboard wiegand library to read the data.
I wrote my own wiegand code. Its not that difficult. I attached interrupts to the data pins and when they change I log the zero or one. You then build up the binary string and once timed out because no bits coming in. Then you convert the binary to decimal.
#include <LiquidCrystal.h>
int data0 = 2; //set wiegand data 0 pin
int data1 = 3; //set wiegand data 1 pin
unsigned long bit_holder; //unsigned long (positive 32 bit number)
unsigned long oldbit = 0;
volatile int bit_count = 0;
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
unsigned long badge;
unsigned int timeout;
unsigned int t = 800;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Present Badge");
delay(2);
Serial.println("Present Badge");
pinMode(data0, INPUT);
digitalWrite(data0, HIGH);
pinMode(data1, INPUT);
digitalWrite(data1, HIGH);
attachInterrupt(0, zero, FALLING); //attach interrupts and assign functions
attachInterrupt(1, one, FALLING);
}
void zero(){
bit_count ++;
bit_holder = (bit_holder << 1) + 0; //shift left one and add a 0
timeout = t;
}
void one(){
bit_count ++;
bit_holder = (bit_holder << 1) + 1; //shift left one and add a 1
timeout = t;
}
void loop() {
timeout --;
if (timeout == 0 && bit_count > 0){
lcd.clear();
lcd.print("Dec:");
lcd.print(bit_holder);
lcd.setCursor(0,1);
lcd.print("Hex:");
lcd.print(String(bit_holder,HEX));
Serial.print("bit count= ");
Serial.println(bit_count);
Serial.print("bits= ");
Serial.println(bit_holder,BIN);
oldbit = bit_holder; //store previous this value as previous
bit_count = 0; //reset bit count
bit_holder = 0; //reset badge number
}
}
You may need to find a reader that offer a continuously reading, as I know almost of Wiegand Reader in the market can't perform a continuously reading because they have a "onboard" control that controls this...
Maybe you can try with Arduino Serial RFID Reader...
try a this timer libary Timer1 and mayby try this code it worked for me, my tags and cards now reads continuously.
Greetings from Denmark
Gregor
#include <Timer1.h>
//******************************************************************
// ATmega168, ATmega328:
// - Using Timer 1 disables PWM (analogWrite) on pins 9 and 10
// ATmega2560:
// - Using Timer 1 disables PWM (analogWrite) on pins 11 and 12
// - Using Timer 3 disables PWM (analogWrite) on pins 2, 3 and 5
// - Using Timer 4 disables PWM (analogWrite) on pins 6, 7 and 8
// - Using Timer 5 disables PWM (analogWrite) on pins 44, 45 and 46
//******************************************************************
unsigned int lastTime;
#include <SoftwareSerial.h>
SoftwareSerial RFID = SoftwareSerial(2,4);
char character;
String our_id;
void setup()
{
// Disable Arduino's default millisecond counter (from now on, millis(), micros(),
// delay() and delayMicroseconds() will not work)
disableMillis();
// Prepare Timer1 to count
// On 16 MHz Arduino boards, this function has a resolution of 4us
// On 8 MHz Arduino boards, this function has a resolution of 8us
startCountingTimer1();
lastTime = readTimer1();
Serial.begin(9600);
RFID.begin(9600);
}
void loop()
{
unsigned int now = readTimer1();
while (RFID.available()>0)
{
character = RFID.read();
our_id += character;
lastTime = now;
}
if (our_id.length() > 10) {
our_id = our_id.substring(1,13);
Serial.println(our_id);
our_id = "";
}
delay(1000);
}
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);
}
}`