hello Everybody!
I have a question for ARDUINO MICRO
I found on the folder C:\Program Files\Arduino\hardware\arduino\avr\variants\micro
this code:
PORTB &= ~(1<<0)
#define RXLED1
PORTB |= (1<<0)
What does it means?
It is refered to arduino LEONARDO of course, what I could understand that the digital PIN are in different position with respect arduino LEonardo. or does it means that they are different?
The other question is that I am trying desperatly to work with MCP4091 but I have seriously problem with the pin SPI.
I found in this file C:\Program Files\Arduino\hardware\arduino\avr\variants\leonardo
After googling an image of Arduino Micro, I can confirm that the pin numbers have not changed...
After thinking about my experience, I believe you are talking about a Pro Micro? or a Mini? It sounds like you are talking about Mini.
As to your first question, PORTB is a register inside the microprocessor, when you set its value, you are setting the pins output. So, PORTB |= (1<<0) is setting bit 0 of PORTB to 1, this just so happens to be the RX LED, and thus turns the LED on.
And for your second question, I dont believe you need to change anything, when you select the correct board and upload, the pins should be automatically configured because the compiler used a different file to determine the pin numbers and their purposes. (I could be wrong, but thats what I took from it)
thanks for the explanation of PORTB I had completely misundertood!
For the PIN position they are still the same in arduino micro e leonardo.
REgarding the question of SS_PIN 10 is that correct or I need to put 17? that it was not clear for me.
Thank you a lot!
THE CODE EXAMPLE TO USE MCP4901 WITH ARDUINO MICRO IS THE FOLLOWING.
#include <SPI.h> // Remember this line!
#include <DAC_MCP49x1.h>
// The Arduino pin used for the slave select / chip select
#define SS_PIN 17
// Set up the DAC.
// First argument: model (MCP4901, MCP4911, MCP4921)
// Second argument: SS pin (10 is preferred)
// (The third argument, the LDAC pin, can be left out if not used)
DAC_MCP49x1 dac(DAC_MCP49x1::MCP4901, SS_PIN );
void setup() {
// Set the SPI frequency to 1 MHz (on 16 MHz Arduinos), to be safe.
// DIV2 = 8 MHz works for me, though, even on a breadboard.
// This is not strictly required, as there is a default setting.
dac.setSPIDivider(SPI_CLOCK_DIV16);
dac.setPortWrite(false);
// dac.setGain(2); if you want a gain of 2
}
// Output something slow enough that a multimeter can pick it up.
// Shifts the output between 0 V and <VREF> (5 volts for many, but not
// necessarily!).
// For MCP4911, use 1023 instead of 255.
// For MCP4921, use 4095 instead of 255.
void loop() {
dac.output(0);
delay(2000);
dac.output(255);
delay(2000);
}
I HOPE ALL THE USER OF ARDUINO MICRO WHO HAVE PROBLEM USING THE SPI PINS WILL SEE IT.
SS_PIN 10 IS NOT FOR ARDUINO MICRO
SS_PIN 17 IS FOR ARDUINO MICRO!
The problem is (if I recall) that the SS pin on the Pro Micro is pin #17, however, it is NOT broken out to an I/O pin for use..
Instead it is hardwired/tied to the yellow, RX led.. (why? I have no clue why it wasnt broken out).
The Pro Micro is supposed to be a pin compatible with the Pro Mini...
However there are some differences..
1.) The SS hardware pin is no broken out as we discussed above.
2.) Where the Pro Mini has TX, RX, RST, GND.. the Pro MICRO has: TX, RX, GND, GND.. meaning the RESET pin is NOT located in the same place as the Pro MINI..
(meaning the Pro MICRO only has 1 RESET pin broken out.. where as the Pro MINI has two, 1 on each side/rail)
As with most SPI bus devices.. I believe you can use ANY pin you want as the SS pin though (re-mapping to pin #10 to be compatible with the MINI..etc.. or whatever pin you need)
You will probably need to turn pin #17 (hardware SS) to an output to designate it as the master...
For the full sized Micro (not Pro Micro).... I think the pins ARE broken out for you.. at least in a specific header pin grouping (ISCP)..etc.