robtillaart / ad520x Goto Github PK
View Code? Open in Web Editor NEWArduino library for SPI AD5204 and AD5206 digital potentiometers
License: MIT License
Arduino library for SPI AD5204 and AD5206 digital potentiometers
License: MIT License
Might overwrite non default parameters.
Hi,
I noticed that using pot.setValue(0, x) and pot.setValue(1, x) has effect on potentiometer 1 both in half scale.
Similarly, using pot.setValue(2, x) and pot.setValue(3, x) has effect on potentiometer 2.
Could not find effect on potentiometer 3 and 4.
ESP32-S3 does not do VSPI.
ESP32 dependency should be minimized
(remove HSPI/VSPI references, see MCP_DAC #24)
I do have a couple of questions as I am trying to use it with a circuitpython project and there is no library for it. I looked through your library and I'm a newb with libraries. Is the baudrate 16000000?
Do you set the mode and the phase?
What is the format of the data sent to the chip?
I'm close to having it work but it's hit or miss if the chip reacts to the command or not
Thanks!!
Constructor for HW SPI should have a pin for select the chip.
Hi,
I was playing around with the AD8403 chip and I noticed that Shutdown and Reset logic are inverted.
They're both active LOW. In fact, if shutdown is LOW, the output is disabled. Looking deep into the library source it's exactly the opposite. Cannot understand how it works with AD5204 as it shares the same logic principle.
See MCP_DAC how to do HSPI / VSPI etc.
I'm trying to use this code for an adafruit ESP32-S2 board using the 2.0.0 release of the arduino IDE and I get the following error:
`c:\Users\aerejb\Documents\Arduino\libraries\AD520X\AD520X.cpp: In member function 'void AD520X::begin(uint8_t)':
c:\Users\aerejb\Documents\Arduino\libraries\AD520X\AD520X.cpp:61:28: error: 'VSPI' was not declared in this scope
mySPI = new SPIClass(VSPI);
^~~~
c:\Users\aerejb\Documents\Arduino\libraries\AD520X\AD520X.cpp:61:28: note: suggested alternative: 'SPI'
mySPI = new SPIClass(VSPI);
^~~~
SPI
Compilation error: exit status 1`
My sketch is as follows:
#include "AD520X.h"
uint32_t start, stop;
// select, reset, shutdown, data, clock
AD8400 pot(10, 255, 255, 11, 13); // SW SPI
// define inputs
const byte right_turn_input = A1;
const byte left_turn_input = 5;
const byte on_off_input = A3;
const byte speed_input = A2;
// define outputs
const byte right_turn_output = 2;
const byte left_turn_output = 4;
const byte on_off_output = 6;
const byte speed_output = 3;
// define variables
int speed_value = 0;
int satelite_count = 0;
bool motor_state = false;
float motor_offset_angle = 0;
float magnetic_declination = 0;
float boat_heading = 0;
float desired_heading = 0;
double actual_lattitude = 0;
double actual_longitude = 0;
double desired_lattitude = 0;
double desired_longitude = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Begin program");
pot.begin(0); // set initial potentiometer value to zero (this gives you the wiper resistance 50-100 ohms)
// define pin inputs
pinMode(right_turn_input, INPUT);
pinMode(left_turn_input, INPUT);
pinMode(on_off_input, INPUT);
pinMode(speed_input, INPUT);
// define pin outputs
pinMode(right_turn_output, OUTPUT);
pinMode(left_turn_output, OUTPUT);
pinMode(on_off_output, OUTPUT);
pinMode(speed_output, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10);
on_off();
if (motor_state == true) {
speed_calculation();
steering_calculation();
}
//Serial.println(" ");
}
void speed_calculation() {
// figure out what the speed value is
speed_value = analogRead(speed_input) / 4;
if (speed_value > 256) { speed_value = 256; }
if (speed_value < 20) { speed_value = 0; }
pot.setValue(0,speed_value); // Set digital potentiometer value for the motor to read
//analogWrite(speed_output, speed_value);
Serial.print("Output speed value = "); Serial.print(speed_value); Serial.print(", ");
}
void steering_calculation() {
// figure out what the steering should change
if (digitalRead(right_turn_input) == 1) {
digitalWrite(left_turn_output, 0);
digitalWrite(right_turn_output, 1);
Serial.print("Turn Right, ");
}
delay(5);
if (digitalRead(right_turn_input) == 0) {
digitalWrite(right_turn_output, 0);
Serial.print("deactivate right turn, ");
}
delay(5);
if (digitalRead(left_turn_input) == 1) {
digitalWrite(right_turn_output, 0);
digitalWrite(left_turn_output, 1);
Serial.print("Turn Left, ");
}
delay(5);
if (digitalRead(left_turn_input) == 0) {
digitalWrite(left_turn_output, 0);
Serial.print("deactivate left turn, ");
}
delay(5);
}
void on_off() {
motor_state = digitalRead(on_off_input);
digitalWrite(on_off_output, motor_state);
if (motor_state == true) {
Serial.println(", Motor on");
}
else {
Serial.println(", Motor off");
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.