Shoryuken Posted November 15, 2015 Report Share Posted November 15, 2015 Hi, I'd like to implement some buttons from DFRobot to my Retrocade Synth.I naively believed that I could just connect the 3 wires to the analog input but maybe that's not that simple.And I don't know which pin number I have to listen... so I've tried every possible pin number but I always get "key = 0" even if I press a button. Could someone help me ? Please see my code and the wiring below. #include "SPIADC.h" #include "SPI.h" int pin = 32; int key_in = -1; int last_key = -1; void setup() { Serial.begin(115200); Serial.println("BEGINNING"); } void loop() { key_in = analog.read(pin); if (key_in != last_key) { Serial.print("key = "); Serial.println(key_in); last_key = key_in; } } Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted November 16, 2015 Report Share Posted November 16, 2015 Hello, It looks like you should be really close to having it work, the only thing that is missing is defining how the SPI ADC is connected, we need to tell the library which Wishbone slot we are using and what CS pin to use. Please try to add this to your setup function (this is for ADC1):analog.begin(CS(WING_CH1),WISHBONESLOT(8),ADCBITS(SPIADC_12BIT));Or, if you want to use ADC2:analog.begin(CS(WING_CL5),WISHBONESLOT(6),ADCBITS(SPIADC_12BIT));Please note that you can get this information by clicking the "View Schematic" icon in DesignLab when you have the RetroCade Synth project opened. This is assuming that you have the RetroCade Synth bit file loaded to the Papilio. Let me know if this works. Jack. Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted November 16, 2015 Report Share Posted November 16, 2015 Oh, I just noticed that there needs to be a change in your analog.read(x) call. With our implementation analog.read(x) will read the channel instead of the pin. Since you are connecting to channel 0 of ADC1 then you will want to do: analog.read(0); Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted November 16, 2015 Report Share Posted November 16, 2015 There is also an example in DesignLab that you can test with. If you go to the table of contents and search for the Analog SPI Wing project there is an existing code example for communicating with the SPI ADC. You will just need to load the RetroCade Synth bit file and change the analog.begin lines to match how the ADC is connected (like posted above). Jack. Quote Link to comment Share on other sites More sharing options...
Shoryuken Posted November 16, 2015 Author Report Share Posted November 16, 2015 Thanks a lot Jack ! Now it works Here's the full code : #include "SPIADC.h"#include "SPI.h"int pin = 0;int key_in = -1;int last_key = -1;void setup(){ analog.begin(CS(WING_CH1),WISHBONESLOT(8),ADCBITS(SPIADC_12BIT)); Serial.begin(115200); Serial.println("BEGINNING"); }void loop(){ key_in = analog.read(pin); if (key_in != last_key) { Serial.print("key = "); Serial.println(key_in); last_key = key_in; }} Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted November 16, 2015 Report Share Posted November 16, 2015 Yay! Glad to see it working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.