Hi i've got a program to control a radar using lidar.
This is the code
//Include Libraries
#include <Stepper.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include "TFMini.h"
#include <AccelStepper.h>
#include <Arduino_FreeRTOS.h>
//Definitions Motor
#define dirPin 4
#define stepPin 5
#define motorInterfaceType 1
int speed = 500;
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
//Definition Encoder
int pinA = 2;
int pinB = 3;
int encoderPosCount = 0; //EEPROM.read(encoderPosCount);
int encoderInterrupt = 0;
int pinALast;
int aVal = 0;
int address = 0;
void TASKMOTOR(void *pvParameters);
void TASKLIDAR( void *pvParameters);
void setup()
{
/* //Encoder Setup
pinMode (pinA,INPUT);
pinMode (pinB,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pinB), rotation, CHANGE);
pinALast = digitalRead(pinA); */
xTaskCreate(
TASKMOTOR
, (const portCHAR *)"Motor"
, 128
, NULL
, 2
, NULL
);
xTaskCreate(
TASKLIDAR
, (const portCHAR *)"Lidar"
, 128
, NULL
, 1
, NULL
);
}
void loop()
{
}
void TASKMOTOR(void * pvParameters)
{
(void) pvParameters;
//Motor Setup
stepper.setMaxSpeed(1000);
for(;;)
{
// Set the speed in steps per second:
digitalWrite(dirPin,HIGH);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
vTaskDelay(2000);
digitalWrite(stepPin,LOW);
vTaskDelay(2000);
}
}
}
void TASKLIDAR(void * pvParameters)
{
(void) pvParameters;
// Setup Serial Port LIDAR
SoftwareSerial mySerial(12, 13);
TFMini tfmini; // Uno RX (TFMINI TX), Board TX (TFMINI RX)
//Lidar Setup
Serial.begin(38400);
Serial.println ("Serial Port Found");
mySerial.begin(TFMINI_BAUDRATE);
tfmini.begin(&mySerial);
for(;;)
{
uint16_t dist = tfmini.getDistance();
uint16_t strength = tfmini.getRecentSignalStrength();
Serial.println(dist);
Serial.print(" cm sigstr: ");
Serial.println(strength);
}
}
void rotation()
{
aVal = digitalRead(pinA);
if (aVal != pinALast)
{
if (digitalRead(pinB) != aVal) //We're Rotating Clockwise
{
encoderPosCount --;
Serial.println ("Rotate Clockwise");
encoderInterrupt = encoderInterrupt + 1;
}
else if(encoderPosCount == 118)
{
encoderPosCount = 0;
}
else
{
Serial.println("Rotate Counterclockwise");
encoderPosCount++;
encoderInterrupt = encoderInterrupt - 1;
}
}
Serial.print("Encoder Count: ");
Serial.println(encoderPosCount);
EEPROM.write(address, encoderPosCount);
Serial.println();
pinALast = aVal;
}
It verifies fine but on uploading i get this message
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/Users/administrator/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
User configuration file is "/Users/administrator/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/cu.usbmodem14101
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
and the upload fails.
Any suggestions to fix this?
Thanks