-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
passing SPIClass for ESP32 pin remapping #11
Comments
@wBrhy2 , you are right. I thought it was a good idea to "outsource" SPI.begin() to the library, but maybe it wasn't. I have updated the library (version 2.2.3) and now you can pass the changed SPI pins when creating the ADXL345_WE object. You find the details in the example sketch ADXL345_SPI_basic_data.ino. It works fine on my side. |
That's amazing, thank you, because my SPI.h was throwing up errors when I was trying to give it different default pins for some reason, so this is very much appreciated! |
Hi @wollewald There is also a problem when using the esp8266. **...\EletroProjects\libraries\ADXL345_WE\src\ADXL345_WE.cpp:27:56: error: no matching function for call to SPIClass::begin(int&, int&, int&, int&)' ...\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SPI/SPI.h:56:8: note: candidate: 'void SPIClass::begin()' The program is looking for SPI i think... What's happening? thanks in advance |
@Ricardosgeral , you are right. This was an unwanted side-effect of my last release. I had added the function: _spi->begin(sckPin, misoPin, mosiPin, csPin); ...to enable users to change the SPI pins for ESP32 boards. This causes a compiler error on non-ESP32 boards, eventhough it's not used on these boards. I have now embraced this function by an #ifdef ESP32 clause. I have tried it and it works. Thanks for raising the issue and sorry for the inconvenience! |
Thank you Wollewald.
Great work.
I appreciate it
A quinta, 27/04/2023, 19:45, Wolfgang (Wolle) Ewald <
***@***.***> escreveu:
… @Ricardosgeral <https://github.com/Ricardosgeral> , you are right. This
was an unwanted side-effect of my last release. I had added the function:
_spi->begin(sckPin, misoPin, mosiPin, csPin);
...to enable users to change the SPI pins for ESP32 boards. This causes a
compiler error on non-ESP32 boards, eventhough it's not used on these
boards. I have now embraced this function by an #ifdef ESP32 clause. I have
tried it and it works.
Thanks for raising the issue and sorry for the inconvenience!
—
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHIREUCGSZ4PGXJF7J2CRP3XDK5DVANCNFSM6AAAAAAXJ6HFFI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Maybe I had same problem?But I mixed other lib and solved it.... // #define MOSI_PIN 23
// #define MISO_PIN 19
// #define SCK_PIN 18
//ADXL345_WE myAcc = ADXL345_WE(&SPI, CS_PIN, spi, MOSI_PIN, MISO_PIN, SCK_PIN); But when I use "tft_espi" lib,it will config SPI pins too. |
@yukiloh , this should be a different issue. Basically the solution for the original issue related with ESP32 boards worked, but it had a side effect on other boards. I also fixed that for the other boards (tried with an Arduino Nano) and it still also worked on the ESP32. So, which ESP32 are you using (i.e. which board do you select in the Ardino IDE)? And what is the problem you experienced? Is it the error message that Ricardosgeral received? I need this information to solve the issue, because otherwise it's difficult to to work on a problem that I can''t reproduce. |
I used ESP32-WROOM-32D modules and customed pcb. Error message is:
I check the code
Try to print the result:
Not very familiar for these code so I gived up... And I checked the
So I try to changed the code in If mix two lib,it will work nice, looks like: And...I just report this problem(not a new issue) |
@yukiloh , thank you for all the information, I really appreciate that. And I don't want to steal more of your time than necessary. Believe me, it is a new issue. The original issue was to add a new feature and unfortunately this lead to another issue on non-ESP32 boards. I fixed it and it works at least on ESP32, ESP8266 and ATmega328P based boards. However, it does not work on your side, so there must be a difference between what I do and what you do. The hint that it works if you mix the libs will probably be very helpful, but only after I have reproduced the issue. Otherwise it's difficult for me to work on that. I have just tried it again and the following sketch works on an ESP32-WROOM-32 Board:
Do you have the chance to try this one? For my trials I used the Arduino IDE 1.8.19 and 2.1.0. Both use the ESP32 Package 1.0.6. The Board I have chosen is "ESP32 Dev Module": Can you provide the complete sketch that is not working on your side? Or at least the first part from the beginning to the point when you have include all libraries and initiated all objects? I know you only report the problem. But need your help to reproduce the issue. |
@wollewald Serial print: (I moved the device,so Raw-x is changing)
It looks the sensor is working,just got the wrong data? And here is my code,set #define USE_TFT 01 // set 0 to OFF,1 to enable TFT_eSPI
#if USE_TFT
#include "TFT_eSPI.h"
#define POW_PIN 12
#define ROTATION 2
TFT_eSPI tft;
//to show the message on the screen
void show_msg(const String &msg, uint8_t order, bool is_first = false);
#endif
#include "ADXL345_WE.h"
#include <SPI.h>
#define CS_PIN 2
#if USE_TFT
ADXL345_WE myAcc = ADXL345_WE(CS_PIN, true);
#else
#define MOSI_PIN 23
#define MISO_PIN 19
#define SCK_PIN 18
bool spi = true;
ADXL345_WE myAcc = ADXL345_WE(&SPI, CS_PIN, spi, MOSI_PIN, MISO_PIN, SCK_PIN);
#endif
void setup() {
Serial.begin(115200);
delay(1000);
#if USE_TFT
/* tft settings,in file "User_Setup.h"
* #define TFT_MISO 19 //SDO
* #define TFT_MOSI 23 //SDI
* #define TFT_SCLK 18
* #define TFT_CS 5 // Chip select control pin
* #define TFT_DC 4 // Data Command control pin
* #define TFT_RST 17 // Reset pin (could connect to RST pin)
* #define TFT_BL 15 // LED back-light
* */
tft.init();
pinMode(TFT_BL, OUTPUT); //screen LED light
digitalWrite(TFT_BL, HIGH);
tft.setRotation(ROTATION);
Serial.println("tft init done");
#endif
Serial.println("ADXL345_Sketch - Basic Data");
if (!myAcc.init()) {
Serial.println("ADXL345 not connected!");
}
myAcc.setCorrFactors(-259.0, 243.0, -86.0, 425.0, -68.0, 439.0);
myAcc.setDataRate(ADXL345_DATA_RATE_25);
delay(100);
Serial.print("Data rate: ");
Serial.print(myAcc.getDataRateAsString());
myAcc.setRange(ADXL345_RANGE_4G);
delay(1000);
Serial.print(" / g-Range: ");
Serial.println(myAcc.getRangeAsString());
Serial.println();
}
void loop() {
xyzFloat raw = myAcc.getRawValues();
xyzFloat g = myAcc.getGValues();
Serial.print("Raw-x = ");
Serial.print(raw.x);
Serial.print(" | Raw-y = ");
Serial.print(raw.y);
Serial.print(" | Raw-z = ");
Serial.println(raw.z);
Serial.print("g-x = ");
Serial.print(g.x);
Serial.print(" | g-y = ");
Serial.print(g.y);
Serial.print(" | g-z = ");
Serial.println(g.z);
Serial.println();
#if USE_TFT
uint8_t order = 0;
show_msg(String(raw.x), ++order, true);
show_msg(String(raw.y), ++order);
show_msg(String(raw.z), ++order);
show_msg(String(g.x), ++order);
show_msg(String(g.y), ++order);
show_msg(String(g.z), ++order);
#endif
delay(1000);
}
void show_msg(const String &msg, uint8_t order, bool is_first) {
uint8_t span = 20; //px,font height is 16px
if (is_first) {
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.setTextColor(TFT_WHITE, TFT_BLACK, true);
}
tft.drawString(msg, TFT_HEIGHT / 2, 10 + span * order, 2);
}
I designed the PCB,so I have no adxl345 module(only the chip)... I'll buy a new adxl345 module to test it,and if it's still not good I will create a new issue. |
Hi @yukiloh , this is a miracle to me, but I like challenges! It will be interesting to see if the ADXL345 you ordered will work. Let me think in the meantime about this issue. Initial thoughts: Sometimes incompatibilities of libraries could occur, but then at least the code I sent should have worked. So it might be related to the wiring. Not saying you did anything wrong! But maybe there is something different between your wiring and the wiring of the modules which requires different settings for SPI. |
Only one small question in between: When you tested the code I sent, you have probably changed the CS pin to 2, right? I ask because I think this is hardwired on your PCB. Anything else you changed? |
I tried a bit. Still I can't say why the code I sent is not working on your PCB as long as you took the right CS pin and didn't change or added anything else. Things I found:
|
Sorry for the slow reply,I am enjoying a public holiday...(dragon-boat-festival) 2.CS will inactive when it is HIGH,and downloading mode need it be DOWN,maybe this is why you can't upload sketch?
|
There does not seem to be support for passing along SPIClass to define which pins to use on the ESP32.
The text was updated successfully, but these errors were encountered: