text:
How can I turn this into an (Ableton) controller?
I found this lovely decade box in a demolished house recently and want to turn it into an Ableton controller. As you see, there are 18 knobs, each with 12 individual states.
I'd like to have a program which can access the states of all the knobs at any time, and I have an arduino which I can use. Is this possible to do without a shield?
My first thought is that, since many of the leads on the back already have resistors on them, I could use a sort of total-resistance-across-the-connection approach which would suit itself to the analog inputs. But I'm not sure that's the way to go, especially if I want very low latency.
How can I wire up a board that has digital access to all the pins here? How does a multiplexer play into this? How many inputs would I need? I am super new to this kind of stuff, so I imagine this must be a pretty simple answer.
Thanks for your help.

The other answers are excellent, however I want to address this question:

How does a multiplexer play into this?

Just as an example of how multiplexing helps, I opened up a scrolling LED sign which has 504 individual LEDs which "appear" to be all on at once (if wanted).
Internally were 10 x 74HC595 serial shift registers. 9 of them were hooked up to the individual columns (giving 72 columns), and the last one was connected to the 7 rows.
 9 * 8 =  72    columns
72 * 7 = 504    LEDs

Thus we could turn on 504 LEDs. However to have individual LEDs appear to come on the code has to turn on one row (out of the 7) and then output the pattern for that row to the 72 columns. Then it switches to another row, does the next pattern, and so on.
I have a video of this effect on Vimeo.
If you do it fast enough, all the LEDs appear to be one at once.

Now you can do this for switches too, just connect all the individual positions together, and then apply "power" to each switch in sequence, and read the results. This time you want an input shift register, eg. the 74HC165 for the reading, and an output register for powering each switch.
The problem is with switches though, that you would get "phantom" reads because switches aren't diodes (or, worse, the inactive switches would short the power to ground). So you would need a diode in series with each switch to prevent that. Ah well, diodes are cheap.
This is exactly the same concept as the way keypads work. Say, a 16-key keypad will have 8 wires: 4 rows and 4 columns.

Having said all that, you will still need quite a few chips unless you set up quite a complex "simulated" keypad array. Maybe it wouldn't be too bad.
You have 17 switches so that would be 2 x 74HC595 for activating each switch, plus one spare pin on the Arduino. And the switches seem to have around 12 positions, so that would be 2 x 74HC165 to read which position it was at.
So, for each switch, you make that one HIGH and the others LOW. Current will flow through the diodes and the rotary switch, presenting a HIGH on one of the 12 "reading" pins. The diodes stop the current from shorting the HIGH to the LOW through other switches.
You take a reading, and move onto the next switch. This can be done quickly, in the same way the LED sign scrolls so fast you can't spot any flickering.
This schematic illustrates the idea:

In this example we apply a HIGH to the common part (rotor) of the left switch. It goes through the diode, and the selected position, to make input "read 1" high. The diode on the other switch prevents the HIGH from being shorted to the LOW, even though both switches are in the same position.
You would need a pull-down resistor for each of the 12 "reading" lines, so that if they weren't being forced HIGH, they would read LOW. And one diode per rotary switch. So, not too many extra parts. And the wiring is simple, just connect each corresponding switch pin together (except for the common one, of course).
I think this will work, unless anyone can see a major flaw. :)

Wow, this is great! Thanks so much. The LED example really helps to illustrate the point. I think this idea is workable, and seems like it would be pretty cheap.

I'm beginning to think Nick is some sort of super human. How else do you explain being able to generate so many high quality, educational solutions? :D

You can use the analog route by using a CD74HC4067, then you can hook it up to a analog demultiplexer, such as the CD74HC4067(breakout from SFE) which has 16 analog/digital inputs. You would use one of these and two analog pins, one from the breakout and one from the panel, as there are 17 dials from what I can see.
An example of a resistor ladder:

The 4067 is addressed using 4 digital pins to make up a binary address relating to each input. You would put this into a for loop and read from each address and put in an array of values each time you loop. And when leaving the loop read the last analog value.
I would use port manipulation to write the address as it would speed up the operation.
Once you have the values in the array you can then do the math require to get where the dial is or you can do that as you read the analog pin the the for loop, kind of keep it all in one function. You can find the calculation for converting in the Wikipedia article, the R-2R style.
Bildr have a nice write up with some code, an image of the basic setup:

The hard part here is that you essentially have 216 inputs you need to read.
You could multiplex the analog pins using two 74HC4051. Analogread takes around 0.1ms, so around 2ms for all 18 knobs. Debouncing would however be pretty hard.
I'd probably go with input shift registers, and remove all the resistors. You would however need 27 8-bit shift register (3 registers per 2 knobs).
To reduce this you could encode the rotary position into 4-bit using a diode network. That way you can use only 1 shift register per 2 knobs. So 9 in total.


text:
Will it work ? MPU6050 Gyro etc. etc. module
Will this code read the values properly ?
Using MPU6050.h.
#include <MPU6050.h>
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin();
  MPU6050.initialize();
}

void loop() {
  MPU6050.getWaitForExternalSensorEnabled();
  float X = getRotationX();
  float Y = getRotationY();
  float Z = getRotationZ();
  Serial.print("X:");
  Serial.println(X);
  Serial.print("Y:");
  Serial.println(Y);
  Serial.print("Z:");
  Serial.println(Z);
}

Please be patient. I know nothing about gyroscope's working.
I'm stupid.

Code would normally look like this
#include <MPU6050.h>
#include <Wire.h>

MPU6050 mpu;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  mpu.initialize();
}

void loop() {

  //what is this doing for you?
  mpu.getWaitForExternalSensorEnabled();

  if(mpu.getIntDataReadyStatus() == 1) {
        float X = mpu.getRotationX();
        float Y = mpu.getRotationY();
        float Z = mpu.getRotationZ();
        Serial.print("X:");
        Serial.println(X);
        Serial.print("Y:");
        Serial.println(Y);
        Serial.print("Z:");
        Serial.println(Z);
  } else
  {
        Serial.println("MPU not ready");
  }

}

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Will 12.6v really damage my arduino?
I'm using a 12v fan and 12v LED modules in my project, so I need about 400mA by their combined specs. I have a 12.6v dc regulated power source that can give ~700mA I wish to use, and since it has a rather small form factor I would also like to power my Arduino Diecimila with it. I'm using PWM from pins 10 and 6 to go through N-channel MOSFETs in order to control both the LEDs and the fan. Anyway, in the Arduino Diecimila board page it says the recommended voltages are between 7-12v, and beyond that it can handle 6-20v, but it might cause the voltage regulator to heat too much, which might damage the board. So, my question is that: will 12.6v really damage my board, or is it within some margin of error? The actual voltage I got when I checked my power supply was 12.55V. Can I maybe just dial it down a bit somehow?
Thanks in advance,
UriSh.

As you have already noticed, it may cause the 5V regulator to get hotter than would be normally considered reasonable.  However, how hot depends entirely on how much current your board is drawing (not including the 12V devices)- the more current you draw the hotter it will get.
Even at 12V it can get uncomfortably hot.
For running off voltages greater than about 9V I usually recommend using an external 5V switching regulator.  These can be easily and cheaply obtained under the name "UBEC" (Universal Battery Elimination Circuit) and are used extensively in the model aircraft arena.  They don't get hot, can handle large currents, and don't waste power like the on-board linear regulator does.
So you'd connect that to your 12.6V supply, then the 5V output of the UBEC (make sure you get a 5V one) would go straight to the 5V pin of the Arduino, and you wouldn't connect the barrel jack or Vin to anything.
You can also pick up cheap switching regulators on eBay - some are adjustable, so you'd want to make sure you adjust it to 5V first before connecting the Arduino, or if you can adjust it to around 7V then you could power the Arduino through the barrel jack (or Vin) with it and avoid too much heat from the on-board linear regulator.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
How to use String.substring?
I have the following code in which requestLine is always empty and I can't figure out why. request contains a raw HTTP request, and I want to get the first line of the request which contains the method and the URL.
boolean parseRequest(String* request)
{
  int firstEOLAt = request->indexOf('\n');
  if (firstEOLAt < 0)
    return false;
  Serial.println(firstEOLAt);
  String requestLine = request->substring(0, firstEOLAt);
  Serial.println(requestLine);
  // ...rest of the parsing will go here...
  return true;
}

The first println returns 26 as you would expect for the string "GET /ilyen_nincs HTTP/1.1" (25 characters long), but then requestLine is always empty. I wonder why?

GET /ilyen_nincs HTTP/1.1\n is 26 characters long so string indices are from 0 to 25. Since, your second argument in substring(0, firstEOLAt); exceeds the end index of the string, you are running into unexpected behavior as per the documentation and getting an empty string.

Caution: make sure your index values are within the String's length or you'll get unpredictable results. This kind of error can be particularly hard to find with the second instance of substring() if the starting position is less than the String's length, but the ending position isn't.


text:
MQTT client on Arduino + SIM900
I have used the pubsubclient library for Arduino for communicating with an MQTT broker in the past, however the library works only with Ethernet connecction. I need to use GSM in my application and am using the SIM900 at the moment. However, I cannot seem to find any library for MQTT communication using an Arduino as MQTT client and SIM900 as gateway. I found this to be surprising as there must surely be many instances where one would want to upload data from Arduino to a MQTT broker in a mobile scenario where cellular network is the only option (in place of Ethernet). So my questions are:

Is it possible to use the Arduino as MQTT client and SIM900 as gateway for communicating with an MQTT broker? Are there any libraries for the same?
What is the current standard way (gateway / communication protocol) of uploading some sensor data from Arduino to an internet server in a mobile scenario (i.e., where Ethernet is not an option)?

I too had the same problem. Mine was a self powered(battery) arduino sensor kit. I tried many and at last ,as the last resort had to use the usual HTTP requests to send data.

MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog, ElementzGithubRepository
Functionalities:
Auto connect
   Automatically connect to TCP and to MQTT server.

connect function
   This function can be used to connect your client to MQTT broker.
   Use only if you do not use Auto connect functionality.
   Optionally  you can use username, password, WILL topic and WILL Message.

OnConnect CallBack function
   This call back function is called when MQTT connection is established.
   You can call subscription and publish functions inside it (according to your need).

publish function
   This function can be used to publish messages to different topics.
   You can select  QoS levels and RETAIN flag according to your need.

subscribe function
   This function can be used to subscribe messages from different topics.

OnMessage CallBack function
   This callback function is called when messages are received from  subscribed topics
   Topic, TopicLength, Message, MessageLength are the arguments of  OnMessage callback function.
   Inside this, you can write your custom code.

unsubscribe function
   This function can be used to unsubscribe from a previously subscribed topic.

disconnect function
   This function can be used to disconnect your client from MQTT broker.

Keep Alive
   You can specify your KeepAlive duration while initializing.
   Ping requests are sent and received automatically.

Update
Nowadays the easiest solution is to use SIM7600 4G/3G/2G modem. It supports MQTT using AT commands !. For more details the following link can be useful to get started.
https://www.elementzonline.com/blog/using-mqtt-at-commands-with-sim7600-and-arduino-for-gsm-iot-projects

The SIM900 allows creation of TCP sockets through an AT style command language, so this addresses point #1 of the previous comments concern.
This is only half the story though, you'll still need to learn how to create the requests, and handle the responses of the MQTT protocol using the SIM900's protocol.
There may be usable examples to start from in the ESP8266 community, as their style of TCP API looks similar to the SIM900.

Take a look at the FONA library from Adafruit.
https://github.com/adafruit/Adafruit_MQTT_Library/blob/master/examples/mqtt_fona/
The FONA Library uses SIM800 which is a newer version of SIM900. You will find MQTT and FONA within the same library. They also run an MQTT Broker service in adafruit.io

MQTT by definition is a TCP/IP protocol, so if you don't have a TCP/IP stack, then it is a no go.
A common pattern/infrastructure in the IoT is to have your "things" connect to a hub of some kind (via BLE, XBee, or ... etc.) and then the hub will connect to the network and post the data. Another option would be to get a cellular device that provides a data connection (i.e. 2G/3G) and therefore a TCP/IP stack. It looks like the SIM900 only supports calls and texts, and as of this moment I am not aware of such a device that has libraries for Arduino.

Actually, the SIM900 comes with a built-in TCP/IP stack. Also 'pubsubclient' accepts a generic Client, which has defined the usual read(), print(), connect(), etc methods; it is definitely possible to create these methods for a 'SIM900 object' and pass it to the pubsubclient constructor and so achieve MQTT functionality.

These tutorials should help on getting started with MQTT on SIM900 or SIM800.
MQTT Protocol tutorial - LIVE DEMO using Mosquitto and CloudMQTT
https://youtu.be/Oh3ZYAQBTko
This video explains about the main important control packets of MQTT protocol by explaining what each byte in a MQTT packet means and also shows how to send and receive data using TCP and Websockets UI of CloudMQTT.com Control panel. We also learn on  how to use the Mosquitto Open source broker on Windows machine to Publish and subscribe to MQTT message and topics on localhost and to cloud servers with and without Authentication.
MQTT Protocol tutorial using SIM900/SIM800 modules - LIVE DEMO
https://youtu.be/dcpMa2UwEeA
This video demonstrates how you can use the light weight MQTT protocol on the SIM900 or SIM800 GSM modules using TCP over the GPRS connection. Here you will learn, how you can use the SIM900/SIM800 TCP commands to send and receive messages as a publisher and a subscriber in almost realtime.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Is it possible to pass HIGH and LOW values as parameter in a function?
I've created the following function:
void runMotor(int _dir, int _step, int wait){
  digitalWrite(_dir, HIGH);
  for (int x = 0; x < 3200; x++) {
    digitalWrite(_step, HIGH);
    delayMicroseconds(wait);
    digitalWrite(_step, LOW);
    delayMicroseconds(wait);
  }

In the first line inside the function I used the value HIGH as a fixed value. I would like to know if there's a way to pass the values HIGH and LOW as a parameter in this function. Is it possible?
Or should I just create a new function to rotate my step motor to the other side?

HIGH is just an alias for the number 1. LOW is just an alias for the number 0. Anywhere you can use numbers you can use HIGH or LOW equally. You can even use them in math: HIGH + HIGH == 2. The same goes for things like INPUT, OUTPUT, RISING, FALLING, etc. They are just aliases to numbers.

digitalWrite expects the pin and value to be uint8_t type. So you can certainly pass LOW or HIGH to functions.
For example:
void runMotor(int _dir, int _step, int wait, uint8_t value){
  digitalWrite(_dir, value);

What about Analog pins? Are they expected to be uint8_t values as well?

I meant what about the analogRead() function...

What do you mean? You don't pass HIGH or LOW to analogRead. You mean the pin numbers? Yes the pin number is uint8_t as well.


text:
Issue with time-dependant conditional I/O control flow (Arduino UNO)
We are working on a project to control the reaction of a system to a lever, whose position is monitored by two IR sensors at the ends of its travel, the Reward sensor and the Trigger sensor.
There are three modes of action:
Mode1: lever has to start at TriggerSensor, and a success is recorded if and when the lever is moved to RewardSensor
Mode2: lever starts at TriggerSensor and has to be held for 4 seconds. At the end of this interval a tone is played for 2 seconds, the reward interval. Within this 2 seconds, if the lever is moved to the RewardSensor, a success is recorded.
Mode3: same as Mode2, but the initial 4 second timeout is of random length.
We also want to use the following lines:
digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));  //This is to record to our computer the states of the trigger sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));  //This is to record to our computer the states of the reward sensor
to constantly write the state of both sensors to our computer. However, this doesn't work as planned: there are delays between the execution of the mode functions (as described in full code below).Essentially, we are struggling to come up with a suitable way to time things correctly.
Please see full code below
// -----LIBRARIES

//#include <elapsedMillis.h>

// ----CONSTANTS (won't change)

const int TriggerSensorIn = 2;   //  Input from trigger sensor, LOW = broken
const int RewardSensorIn = 3;    //  Input from reward sensor, LOW = broken
const int ModeStateIn1 = 4;      //  Input 1 from switch to define paradigm mode
const int ModeStateIn2 = 5;      //  Input 2 from switch to define paradigm mode
const int RewardSignalOut = 12;   //  Output signal of reward, parallel taken off to counter module
const int ServoResetOut = 6;     //  Servo reset output signal
const int ToneOut = 10;          //  Audio stimulus
const int TriggerSensorOut = 7;  //  Output from trigger sensor for DAC board recording
const int RewardSensorOut = 8;   //  Output from reward sensor for DAC board recording

//------- VARIABLES (will change)

boolean backPressed = false;

int timeoutWindow = 4000;    // 4 second preliminary interval
int rewardWindow = 2000;    // 2 second reward interval

unsigned long currentMillis = 0;

//===============

void setup() {

  // initialise the digital pins as inputs and outputs

  pinMode(TriggerSensorIn, INPUT);
  pinMode(RewardSensorIn, INPUT);
  pinMode(ModeStateIn1, INPUT);
  pinMode(ModeStateIn2, INPUT);

  pinMode(RewardSignalOut, OUTPUT);
  pinMode(ServoResetOut, OUTPUT);
  pinMode(ToneOut, OUTPUT);
  pinMode(TriggerSensorOut, OUTPUT);
  pinMode(RewardSensorOut, OUTPUT);

}

//===============

void giveReward() {
  // This function is the protocol for recording a reward
  currentMillis=millis();
  digitalWrite(RewardSignalOut, HIGH);
  while (millis()>currentMillis+200) {
    digitalWrite(RewardSignalOut, LOW);
  }
}

//===============

void servoReset() {
  // This function is the protocol for resetting servos after a failed action
  currentMillis=millis();
  digitalWrite(ServoResetOut, HIGH);
  while (millis()>currentMillis+200) {
    digitalWrite(ServoResetOut, LOW);
  }
}

//===============

void mode1() {
  // This function is the protocol for controlling the system during mode 1, no time constraint on the action
  if (digitalRead(TriggerSensorIn == LOW)) {
    backPressed = true;

    if (backPressed == true && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
      backPressed = false;
    }
  }
}

//===============

void mode2() {
  if (digitalRead(TriggerSensorIn == LOW)) {
    currentMillis=millis();
    while (digitalRead(TriggerSensorIn == LOW)) {
      while (millis() > currentMillis + timeoutWindow) {
        tone(ToneOut, 3000, 2000);
        {
          goto rewardSeeking2;
        }
      }
    }

rewardSeeking2:
    currentMillis=millis();  // reset timer
    if (millis() < (currentMillis + rewardWindow) && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
    }
    else if (millis() > (currentMillis + rewardWindow)) {
      servoReset();
    }
  }
}

//===============

void mode3() {
  timeoutWindow=random(1000,5000);
  if (digitalRead(TriggerSensorIn == LOW)) {
    currentMillis=millis();
    while (digitalRead(TriggerSensorIn == LOW)) {
      while (millis() > currentMillis + timeoutWindow) {
        tone(ToneOut, 3000, 2000);
        {
          goto rewardSeeking3;
        }
      }
    }

rewardSeeking3:
    currentMillis=millis();  // reset timer
    if (millis() < (currentMillis + rewardWindow) && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
    }
    else if (millis() > (currentMillis + rewardWindow)) {
      servoReset();
    }
  }
}

//===============

void loop() {

  digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));  //This is to record to our computer the states of the trigger sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));  //This is to record to our computer the states of the reward sensor

  if (digitalRead(ModeStateIn1) == LOW && digitalRead(ModeStateIn2) == LOW) {
    // Using the two mode selective switches to define mode1
    mode1();
  }

  else if (digitalRead(ModeStateIn1) == LOW && digitalRead(ModeStateIn2) == HIGH) {
    // Using the two mode selective switches to define mode2
    mode2();
  }

  else if (digitalRead(ModeStateIn1) == HIGH && digitalRead(ModeStateIn2) == LOW)  {
    // Using the two mode selective switches to define mode3
    mode3();
  }
}

//===============END

while (millis() > currentMillis + timeoutWindow) looks wrong to me. I'd think the > should be a < .

Even with a < it would be wrong because of the millis() rollover. The right way to write that would be while (millis() - currentMillis < timeoutWindow).

Goto?  GOTO?!?!?!?!  AAAAAARRRRRGGGHHHH!!!!!!  NO!!!!!

what would you recommend using instead of GOTO, just use break?

Well, goto has its use, see for example the way in the linux kernel device drivers undo partial initialization, when some intermediate test fails.
However here its use seems strange: it's inside a while loop that actually gets executed only once (therefore it could be turned into and "if").
And the execution breaks out of the outer while when the inner condition is verified. Since it's not possible to add readable code to a comment here, I'll try to put it in a separate answer.

Virtually nobody (maybe excepting Linux kernel device driver authors) should need to use goto. It leads to Spaghetti code.

This is a snippet of how I would refactor the code:
void mode3() {
  int timeout = millis() + random(1000,5000);
  while (digitalRead(TriggerSensorIn == LOW) &&
         millis() < timeout) {
  };
  if (digitalRead(TriggerSensorIn == LOW) &&
         millis() > timeout) {
     tone(ToneOut, 3000);
     timeout = millis() + rewardWindow;
     while (millis() < timeout)
       if (digitalRead(RewardSensorIn == LOW)
         giveReward();
  }
  noTone();
}

....
void loop() {
  // This is to record to our computer the states of
  // the trigger sensor
  digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));

  // This is to record to our computer the states of
  // the reward sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));

  int msin1 = digitalRead(ModeStateIn1);
  int msin2 = digitalRead(ModeStateIn2);

  if (msin1 == LOW)
      if (msin2 == LOW)
          mode1();
      else
          mode2();
  else if (msin2 == LOW)
    mode3();
}

But I think you should first try to write it down in plain English and verify that at least that algo works.
Then you can think how to transpose it into code.


text:
Reading SPI between an MCU and NRF24L01
I have a remote control that has an STM32 MCU and sends data via NRF24L01. What I would like to do is clone the data sent when buttons are pressed by reading what is being sent to the RF24 and then replicating these messages with my own "remote".
I have tried sniffing the data wirelessly with my Pro Mini and NRF24L01. I have everything plugged in correctly, the BasicExample seems to be running fine, but when I run a promiscuous channel activity sniffer, I don't get any wireless data, not even running wifi and bluetooth near the NRF. Pro Mini is 5V and NRF sniffer is powered by an external 3.5V battery with cap on VCC-GND, ground is common to Pro Mini. I have also tried the WireShark approach, but with 0 packets found.
Therefore I want to try it directly wired to the remote. I don't have a logic analyzer handy. How would I read the data? By just connecting MISO and CS to an arduino and running an SPI reader? What would be the best way to do this? I have the Pro Mini and many Teensy boards ready.

That was an interesting challenge. There are some obstacles to consider when trying to use RF sniffing:

What channel is used? (128)
What bit-rate is used? (250K-1M-2M)
How many address bytes? (3-5 byte)
How many bits in CRC? (1-2 byte)
Auto-Acknowledgement? (1 bit)
etc.

Without any info on the remote NRF configuration this is tedious to break. Probing the hardware signals (MISO, MOSI, SCK, SS) on the remote NRF chip with a logic analyzer seems (much) easier.
Cheers!

I found this wonderful tutorial http://yveaux.blogspot.com/2014/07/nrf24l01-sniffer-part-1.html but I haven't had any luck receiving anything yet.

First thing you have to make sure you have wired the receiver correctly. (Also download the latest RF24 library from built-in library manager or from github.com/TMRh20/RF24) Then solder at least 100uF capacitor directly to the power pins of the Nrf24l01. If you wish to reverse engineer it, you must make sure it's not your hardware or software letting you down. (When you manage to reverse engineer it, please leave a comment here for others wishing to do the same)


text:
Is there a module that will allow me to pair a bluetooth keyboard to an arduino?
I want to pair a bluetooth keyboard to an arduino project, so that pressing a key on the keyboard causes an action to happen on the Arduino. Let's say that pressing Q on the keyboard makes an LED turn on, and pressing W makes it turn off.
I know that I need some sort of bluetooth module connected to the Arduino, and I need to pair the keyboard to the module. I also know that it must be a module that can act in Master mode and use the HID protocol. But I cannot find a module that does what I want. For example, the HC05 module cannot do HID.
Has anyone done this? Can you tell me which module you used please? I don't want to involve anything else, just an Arduino, a module, and a bluetooth keyboard.

I googled "arduino bluetooth hid host" https://www.circuitsathome.com/mcu/arduino/bluetooth-hid-devices-now-supported-by-the-usb-host-library/

I also looking for a module that could act as a master and support HID!

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
uSDaemon in Linino / Arduino Yun Mini hogging the syslog
There is an annoying problem with Linino One / Arduino Yun Mini as the syslog (logread) is full of messages from uSDaemon, complaining about missing files.
ls: /sys/bus/scsi/drivers/sd/*/block/sd?: No such file or directory
handle umount errors
check umount
(and so on, three lines every two seconds, so every other meaningful information is pushed out of the syslog pretty soon)
If I disable the uSDaemon with
/etc/init.d/usd disable
the syslog is OK, but is there any functionality actually lost if uSDaemon is not running, beside being unable to read from a non-existing uSD card reader?


text:
How to connect Arduino to a switch that doesn't accept 10M?
I've been playing around with several Arduino ethernet modules based on the ENC28J60 and the W5500 chipset. All modules are advertised as 10/100M, but in reality only work when the port of a switch is configured to handle 10M explicitly.
At this point in time that isn't a problem, however I'll be switching to new switches in the near future that can no longer handle 10M, having 100M as the slowest possible port speed.
How can I still connect my Arduino modules to these new switches (specifically Extreme Networks 5720-48MW)? Are there ethernet modules available that can connect to the 5720-48MW switches? And if so, how do I differentiate these modules, since all modules are advertised as 10/100M?

Have you actually determined that your new switches will cause problems?

@StarCat Yes, this is a well known issue, not only limited to these Arduino modules. 10M devices will not work with switches that have speeds of 2.5GBit of higher.

I see now that the ENC28J60 is regularly advertised as supporting 10/100Mbps speeds but according to its datasheet it only supports 10Base-T (10Mbps). The WS5500 should be able to support 10/100 however, if properly implemented.


text:
Static IP configuration failed in NODEMCU
I'm trying to connect NODEMCU to my home network and set static IP address, but the static IP didn't set properly this is the code:
#include <ESP8266WiFi.h>
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.config(IPAddress(192,168,1,129), IPAddress(192,168,1,1), IPAddress(225,225,225,0));
  WiFi.begin("Bam", "123456789");
  Serial.print("\nConnecting");
  while(WiFi.status()!=3){
    Serial.print(".");
    delay(500);
  }
  Serial.println("Connected");
  Serial.println(WiFi.localIP());

}

void loop() {
  // put your main code here, to run repeatedly:

}

and this is the output on the Serial monitor:
13:28:46.715 -> Connecting.......Connected
13:28:50.937 -> 192.168.1.100

when I set the same static IP address to my phone it sets with no problem.

You connect to the WiFi first, then try to change the IP, of course it will not work. Config first, then connect.

@hcheung I forgot to mention all solutions I've tried, I tried this but didn't work

Shouldn't the network mask be 255.255.255.0 rather than 225.225.225.0 ?
Also does anything else on your network have an IP of 192.168.1.129 ?


text:
Motion-activated lights
I am attempting to follow this tutorial to light up a dark staircase with motion-activated LED strips. If my understanding of the tutorial is correct, essentially the Arduino's job is to power or depower transistors at the appropriate time to prohibit/allow enough voltage over the LED strips on the stairs.
I have assembled a few light strips and soldered the microcontroller to the PCB with the appropriate components and was ready to test the device. The author of the guide helpfully created this video demonstrating the expected behavior of the device on start-up: the lights should blink as shown and then turn off, awaiting activation from a motion sensor. However when I try to replicate this my lights simply turn on and never turn off, fade, or blink.
Consulting the FAQ on the guide, I tried reorienting my transistors, thinking I perhaps had them backward. This had no effect.
I then tried to verify that my microprocessor was working and programmed correctly. I modified the code in the setup section, adding the following commands:
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
for(int i=0; i<10; i++){
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(2000);
}

The intention was to make the built-in LED on the board blink on and off a few times during startup. While the board was connected to the computer, it indeed blinked on and off after I hit upload. When it's attached to the power supply from the PCB it does not blink (though the LED lights for the stairs turn on as I have described).
It seems to me that the microprocessor is simply not getting power or is not connected properly to the PCB. However I have done my best to verify all the connections and cannot find any problem. This is my first project of this type and am not sure what else to try. Any guidance with troubleshooting would be very much appreciated.
I apologize for the long post but I wanted to be sure to include all the necessary information. Thank you for reading!
Below are images of the PCB and schematics from the guide, which hopefully correspond to how I've actually connected the components.

Here is the code from the guide plus my blinking loop. The original is available at the author's github.
##Shift_Stairs.ino

#include <math.h>
#include <SPI.h>
//#include <MemoryFree.h>
//#include "expoDutyCycles.h"

//Data pin is MOSI (atmega168/328: pin 11. Mega: 51)
//Clock pin is SCK (atmega168/328: pin 13. Mega: 52)
const int ShiftPWM_latchPin=10;
const bool ShiftPWM_invertOutputs = 0; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

#include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!

const int SWITCH_PIN = A0;
const int PHOTORESISTOR_PIN = A2;
const int MOTION_SENSOR_TOP_PIN = 2;
const int MOTION_SENSOR_BOTTOM_PIN = 3;

const unsigned char maxBrightness = 255;
const unsigned char pwmFrequency = 75;
const int numRegisters = 2;
const int NUMLEDs = 9;
const int MOTION_SENSOR_WARMUP_TIME = 10;
const int ON_TIME = 10000; /* The duration between turn on and turn off. */
const int LIGHT_THRESHOLD = 300; /* Anything below this sensor value will enable lights */

/* These are used to detect rising edges in the absence of interrupts.
   Using interrupts with ShiftPWM crashes the program. */
unsigned char lastReadTopPin = LOW;
unsigned char lastReadBotPin = LOW;

volatile unsigned char topActivated = false;
volatile unsigned char bottomActivated = false;
unsigned long lastMotionTime = 0;

const char BOTTOM_TO_TOP = 1;
const char TOP_TO_BOTTOM = 2;
/* For sake of the animation, stores the direction of propegation.
   Set when animation is active, cleared when animation is done.  */
char directionTriggered = 0;

const unsigned long BRIGHTNESS_SM_PERIOD = 2000; /* in μs */
unsigned long lastBrightnessSM = 0;

/* LED 0 is on the top of stairs */
unsigned char brightnesses[NUMLEDs] = {0};

void setup()   {
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
    for(int i=0; i<10; i++){
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delay(2000);
    }
    pinMode(ShiftPWM_latchPin, OUTPUT);
    SPI.setBitOrder(LSBFIRST);
    // SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte.
    // SPI transfer and calculations overlap for the other bytes.
    SPI.setClockDivider(SPI_CLOCK_DIV4);
    SPI.begin();

    Serial.begin(9600);

    /* Turn on pullup resistor for switch */
    digitalWrite(SWITCH_PIN, HIGH);

    ShiftPWM.SetAmountOfRegisters(numRegisters);
    ShiftPWM.Start(pwmFrequency,maxBrightness);
    // Print information about the interrupt frequency, duration and load on your program
    ShiftPWM.SetAll(0);
    ShiftPWM.PrintInterruptLoad();
    // Fade in all outputs
    for(int j=0;j<maxBrightness;j++){
        ShiftPWM.SetAll(j);
        delay(3);
    }
    // Fade out all outputs
    for(int j=maxBrightness;j>=0;j--){
        ShiftPWM.SetAll(j);
        delay(3);
    }
}
void loop()
{
    /* Detect rising edge with polling. Interrupts crash the program. */
    unsigned char pinRead = digitalRead(MOTION_SENSOR_TOP_PIN);
    if(pinRead == HIGH && lastReadTopPin == LOW){
        topActivated = true;
    }
    lastReadTopPin = pinRead;
    /* Detect rising edge with polling. Interrupts crash the program. */
    pinRead = digitalRead(MOTION_SENSOR_BOTTOM_PIN);
    if(pinRead == HIGH && lastReadBotPin == LOW){
        bottomActivated = true;
    }
    lastReadBotPin = pinRead;

    /* Resets flags */
    if(topActivated){
        if(directionTriggered == 0){
            directionTriggered = TOP_TO_BOTTOM;
        }
        lastMotionTime = millis();
        topActivated = false;
    }
    if(bottomActivated){
        if(directionTriggered == 0){
            directionTriggered = BOTTOM_TO_TOP;
        }
        lastMotionTime = millis();
        bottomActivated = false;
    }

    /* State machine */
    if(micros() - lastBrightnessSM > BRIGHTNESS_SM_PERIOD){
        brightnessSM();
        lastBrightnessSM = micros();
    }
}
/**
    Returns true if switch is in "1" position.
*/
boolean switchPressed(){
    return !digitalRead(SWITCH_PIN);
}

###brightnessSM.ino
enum brightnessStates {
    sFullyOn,
    sOff,
    sTurningOn,
    sTurningOff,
    sOverrideSwitch
};

int brightnessState = sOff;

void brightnessSM(){
    /* Actions */
    switch(brightnessState){
    case sFullyOn:
        break;
    case sOff:
        break;
    case sTurningOn:{
        /* Increase brightness of lights. This for loop goes from -NUMLEDs to 0 or
           0 to NUMLEDs depending on the direction of propegration. */
        char startLight = -1 * (directionTriggered - 1) * (NUMLEDs - 1);
        char endLight   = -1 * (directionTriggered - 2) * (NUMLEDs - 1);
        for(char l = startLight; l <= endLight; l++){

            /* Turn on the next LED only if the ones before it
               are on*/
            if(brightnesses[abs(l)] != maxBrightness){
                brightnesses[abs(l)] += 5;
                ShiftPWM.SetOne(abs(l), brightnesses[abs(l)]);
                break;
            }

            /* Turn on the next LED only if the one before it is partially on */
//            if(brightnesses[abs(l)] != maxBrightness){
//                if(l == startLight || (brightnesses[abs(l - 1)] > maxBrightness*3/10)){
//                    brightnesses[abs(l)] += 1;
//                    ShiftPWM.SetOne(abs(l), expoDutyCycles[brightnesses[abs(l)]]);
//                }
//            }
        }
        break;
    }
    case sTurningOff:{
        /* Decrease brightness of lights. This for loop goes from -NUMLEDs to 0 or
           0 to NUMLEDs depending on the direction of propegration. */
        char startLight = -1 * (directionTriggered - 1) * (NUMLEDs - 1);
        char endLight   = -1 * (directionTriggered - 2) * (NUMLEDs - 1);
        for(char l = startLight; l <= endLight; l++){
            /* Turn on the next LED only if the ones before it
               are on*/
            if(brightnesses[abs(l)] != 0){
                brightnesses[abs(l)] -= 5;
                ShiftPWM.SetOne(abs(l), brightnesses[abs(l)]);
                break;
            }

            /* Turn on the next LED only if the one before it is partially on */
//            if(brightnesses[abs(l)] != 0){
//                if(l == startLight || (brightnesses[abs(l - 1)] < maxBrightness*9/10)){
//                    brightnesses[abs(l)] -= 1;
//                    ShiftPWM.SetOne(abs(l), expoDutyCycles[brightnesses[abs(l)]]);
//                }
//            }
        }
        break;
    }
    case sOverrideSwitch:
        break;
    }

    /* Transitions */
    switch(brightnessState){
    case sFullyOn:
        if(millis() - lastMotionTime > ON_TIME){
            brightnessState = sTurningOff;
        }
        if(switchPressed()){
            transitionToOverrideSwitch();
        }
        break;
    case sOff:
        if(directionTriggered != 0){
            if(analogRead(PHOTORESISTOR_PIN) < LIGHT_THRESHOLD){
                brightnessState = sTurningOn;
            }
            else {
                directionTriggered = 0;
            }
        }
        if(switchPressed()){
            transitionToOverrideSwitch();
        }
        break;
    case sTurningOn:{
        /* If all the lights are on then proceed */
        unsigned char allOn = true;
        for(unsigned char l = 0; l < NUMLEDs; l++){
            if(brightnesses[l] != maxBrightness){
                allOn = false;
                break;
            }
        }
        if(allOn){
            brightnessState = sFullyOn;
        }
        if(switchPressed()){
            transitionToOverrideSwitch();
        }
        break;
    }
    case sTurningOff:{
        /* If all the lights are off then proceed */
        unsigned char allOff = true;
        for(unsigned char l = 0; l < NUMLEDs; l++){
            if(brightnesses[l] != 0){
                allOff = false;
                break;
            }
        }
        if(allOff){
            directionTriggered = 0;
            brightnessState = sOff;
        }
        if(switchPressed()){
            transitionToOverrideSwitch();
        }
        break;
    }
    case sOverrideSwitch:
        if(switchPressed() == false){
            /* Switch all LEDs off */
            for(char l = 0; l < NUMLEDs; l++){
                ShiftPWM.SetOne(l, 0);
                brightnesses[l] = 0;
            }
            directionTriggered = 0;
            brightnessState = sOff;
        }
        break;
    }
}
void transitionToOverrideSwitch(){
    brightnessState = sOverrideSwitch;
    /* Switch all LEDs on */
    for(unsigned char l = 0; l < NUMLEDs; l++){
        ShiftPWM.SetOne(l, maxBrightness);
        brightnesses[l] = maxBrightness;
    }
}

Check the orientation of the Arduino. Is it upside-down? Check also the voltage between the pins labeled GND and VCC.

Thanks for the response. I am reading 12V across the pins which seems good. I'm fairly sure the orientation is correct but I'll double check.

Consulting the schematics it looks like the (knockoff) version of the board I used has the FTDI header oriented the other way around, but the rest of the pins match. I have some spares so I could try it flipped if nothing else works.

Thanks, images added, code will follow. I'd be happy to add anything else you think will be helpful.

Where exactly have you measured 12V? Have you measured between Vcc and ground of the Arduino? 12V would be bad.

what happens if you run a minimal sketch , such as blink builtin LED?

the circuit has no reset ... the outputs are always enabled ... that means that the output may be in any state at power-on ... maybe start with simple sketch to bit-bang the input signals ... set pins 10, 11, 13 LOW, toggle pin 13 LOW-HIGH-LOW sixteen times to shift in all zeros, toggle pin 10 LOW-HIGH-LOW to transfer shifted data to outputs ... delay one second ... set pin 11 HIGH and repeat the pin 13 and pin 10 actions ... that should turn off all of the LEDs and then turn them back on ... pin 11 is data, pin 13 is the serial shift-in clock, pin 10 is the output latch clock

I can get the built-in LED to blink when I have the Arduino hooked up to my computer and I upload the sketch. Nothing happens on the Arduino when I plug in the power supply on the PCB. The code has been verified by other users who have successfully followed the guide so I'd be very surprised if that was the source of the issue. When I have a chance I will try your idea.

your circuit is similar to https://wokwi.com/projects/301213976182653448

Your soldering is really grizzly looking. Not enough heat, no flux, not heating the work before feeding solder... something. Before worrying about much else I would figure out what's up with that, because until then it may just drive you anyone that tries to help you nuts.

The image of the Printed Circuit Board (PCB) posted in the above question contains many examples of what are commonly referred to as Cold Solder Joints.  These types of joints are unreliable and occasionally provide no electrical connectivity. And are often impossible to visually verify.  The first 2 minutes of this video demonstrate how heat and flux can be combined to remedy cold solder joints involving a PCB and feed-through pin.
(I can edit/change the following as we narrow in on the solution for this problem. The objective is to make a good stackexchange question & answer.)
Symptom:

The project behaves as expected when cabled to the PC.  This assumes the cable to the PC (likely to a USB/CDC to Serial Port) contains Ground, In, Out and Power. The expected behavior is to turn the LEDs on and off.
The project does not work when disconnected from the PC and is powered by an external power supply.  The LEDs only turn on.

Consider verifying power to the processor or, better, at the processor.  For the problem as described in the question, there may be an interruption of the power path from the external power supply to the processor.  Check all the solder joints involved in connecting the Arduino's power input to the PCB. Likely the processor (Arduino) was powered up during programming through the Ground and Power pins of the serial port cable.  Once that cable was removed, the processor may not be powered and may have not been running while the PCB was only powered from an external source.


text:
Send data through SPI with DMA
I need to send data as fast as possible from an Arduino DUE to an extern DAC. To do so I use DMA & SPI and I want DMA to fetch data from the memory and send it to the SPI which will just relay it via its Master Output Slave input.
So far I did a DMA transfer from a variable to another, woked perfectly. I'm using the same code but change the address as SPI_TDR (Transmit Data Register), unfortunatly it's not working. I guess the address is not good but if so what should I do ?
Here is my code :
#include <dmac.h>
#include <SPI.h>

#define DMA_CH 0         //N° Canal du DMA
#define DMA_BUF_SIZE 32  //Taille mémoire DMA

uint32_t g_dma_buf2[DMA_BUF_SIZE];

void setup() {
  Serial.begin(9600);
  SPI.begin();

  SPI0->SPI_WPMR = 0x53504900;             //Protection key
  SPI0->SPI_IDR = 0x0000070F;              //Desactivation interrupts
  SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PS;  //SPI master
}

void loop() {
  Serial.println("+++++");
  pmc_enable_periph_clk(ID_DMAC);

  uint32_t i;
  uint32_t cfg;
  dma_transfer_descriptor_t desc;

  for (i = 0; i < DMA_BUF_SIZE; i++) {
    g_dma_buf2[i] = i;
    Serial.print(g_dma_buf2[i]);
  }
   Serial.println();

  dmac_init(DMAC);
  dmac_set_priority_mode(DMAC, DMAC_PRIORITY_ROUND_ROBIN);
  dmac_enable(DMAC);
  cfg = DMAC_CFG_SOD_ENABLE | DMAC_CFG_AHB_PROT(1) | DMAC_CFG_FIFOCFG_ALAP_CFG;  //Config registre CFG
  dmac_channel_set_configuration(DMAC, DMA_CH, cfg);

  desc.ul_source_addr = (uint32_t)g_dma_buf2;
  desc.ul_destination_addr = SPI0->SPI_TDR;
  desc.ul_ctrlA = DMAC_CTRLA_BTSIZE(DMA_BUF_SIZE) | DMAC_CTRLA_SRC_WIDTH_WORD | DMAC_CTRLA_DST_WIDTH_WORD;
  desc.ul_ctrlB = DMAC_CTRLB_SRC_DSCR_FETCH_DISABLE | DMAC_CTRLB_DST_DSCR_FETCH_DISABLE | DMAC_CTRLB_FC_MEM2MEM_DMA_FC | DMAC_CTRLB_SRC_INCR_INCREMENTING | DMAC_CTRLB_DST_INCR_FIXED;
  desc.ul_descriptor_addr = 0;

  SPI_Enable(SPI0);
  dmac_channel_multi_buf_transfer_init(DMAC, DMA_CH, &desc);
  dmac_channel_enable(DMAC, DMA_CH);
  Serial.println("*****");

  while (!dmac_channel_is_transfer_done(DMAC, DMA_CH)) { Serial.print('X'); }
Se
  Serial.print("SR : "); Serial.println(SPI0->SPI_SR, HEX);
  Serial.print("TDR : "); Serial.println(SPI0->SPI_TDR, HEX);
  Serial.print("PSR : "); Serial.println(PIOA->PIO_PSR, HEX);   //PIO_SODR
  Serial.print("OSR : "); Serial.println(PIOA->PIO_OSR, HEX);
  Serial.println(DMAC->DMAC_CH_NUM[0].DMAC_SADDR , HEX);
  Serial.println(DMAC->DMAC_CH_NUM[0].DMAC_DADDR, HEX);
  Serial.println("-----");
}

I use mainly this example : https://ww1.microchip.com/downloads/en/Appnotes/Atmel-42291-SAM3A-3U-3X-4E-DMA-Controller-DMAC_ApplicationNote_AT07892.pdf#_OPENTOPIC_TOC_PROCESSING_d91e3076
And here is the datasheet of the µc : https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf
You can see at the bottom of my code sevral prints, from them I had many idea : does the PIO could block the data ? Does the address PIO_PA26A_SPI0_MOSI could work ? Could the SPI block the data because conditions are not met ?
Any idea is welcomed, I'm on this for some time now.
Edit :  SPI is not an necessity, the idea is to send data without length limit (unlike UART). I'm considering using SSC.

I had a look at the block diagram (section 32.2) and I'm wondering if DMA really can address SPI or if I have to manage some layer in-between.

I managed to solve it but not with SPI, I use the SSC of the µcontroller (which does I²S and uses DMA automatically) :
uint32_t liste[] PROGMEM = { 0x8F66F1, 0x0, 0xAAAAAB };  //Data to send
#define DMA_BUF_SIZE (sizeof(liste) / sizeof(liste[0]))  //Size DMA buffer

uint32_t i;

void setup() {
  uint clk_div = 0x90;  //Clock divider wanted
  clk_div = (clk_div / 24) / DMA_BUF_SIZE;
  clk_div = floor(clk_div + 0.5);
  clk_div = clk_div * 24 * DMA_BUF_SIZE;  //Clock divider adjusted -> MCK/2*clk_div

  PMC->PMC_WPMR = 0x504D4300;                                    //Desactivation protection PMC
  PMC->PMC_PCER0 = (1 << ID_SSC);                                //Activation SSC clock
  PMC->PMC_SCER |= 0x100;                                        //Activation clock
  PIOA->PIO_WPMR = 0x50494F00;                                   //Desactivation protection Port I/O A
  PIOA->PIO_PDR = PIO_PDR_P14 | PIO_PDR_P15 | PIO_PDR_P16;       //I/O controlled by the peripheral
  PIOA->PIO_ABSR |= PIO_PA14B_TK | PIO_PA15B_TF | PIO_PA16B_TD;  //Assignation of I/O to SSC

  SSC->SSC_CR = SSC_CR_RXDIS | SSC_CR_TXDIS | SSC_CR_SWRST;                                                     //Desactivation and reset SSC
  SSC->SSC_WPMR = 0x53534300;                                                                                //Desactivation protection SSC
  SSC->SSC_IDR = 0xFFFFFFFF;                                                                                //Desactivation Interrupts
  SSC->SSC_IER = 0x00000000;                                                                                //Desactivation Interrupts bis
  SSC->SSC_CMR = clk_div;                                                                                //Clock management
  SSC->SSC_TFMR = SSC_TFMR_DATLEN(0x18) | SSC_TFMR_MSBF | SSC_TFMR_DATNB(0);                                    //Data transfert management
  SSC->SSC_TCMR = SSC_TCMR_CKS_MCK | SSC_TCMR_CKO_CONTINUOUS | SSC_TCMR_START_CONTINUOUS | SSC_TCMR_STTDLY(0);  //Clock during transfert management
  SSC->SSC_CR = SSC_CR_TXEN;                                                                                //Activation transmission SSC
}

void loop() {
  for (i = 0; i < DMA_BUF_SIZE; i++) {
    ssc_write((Ssc*)SSC, (uint32_t)liste[i]);  //Transmission SSC
  }
}

In case someone try the same thing.

I believe I have gotten this to work the way you intended, without SSI. Bits of this code have been borrowed from an SD Card library (https://github.com/openbci-archive/OpenBCI_8bit/blob/master/OpenBCI_8bit_SDfat_Library/SdFat/SdSpiSAM3X.cpp, around line 110). I am trying to run a TFT using a "framebuffer," but in order to do so I need DMA working with SPI.
In your original source, it appears you are missing a few things in cfg. According to the aforementioned code listing, cfg should look something like DMAC_CFG_DST_PER(1) | DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD_ENABLE | DMAC_CFG_AHB_PROT(1) | DMAC_CFG_FIFOCFG_ALAP_CFG. Per the datasheet, DST_PER must be set to one of the DMA channels seen on page 339, table 22-2. In this case, Channel 1 is used, as it corresponds to SPI0_TX. Likewise, you appear to be missing DMAC_CFG_DST_H2SEL for hardware handshaking. There's likely a few other things I'm not pointing out, as I had a fair amount of trouble with this too.
TL;DR The following code should do the trick for a basic DMA transfer from a buffer:
#include "sam.h"

#define CLOCK_SPEED 84000000

void setup_spi()
{
    PMC->PMC_PCER0 |= (1 << ID_PIOA); // Enable PIOA

    PIOA->PIO_ODR |= PIO_PA25;      // MISO Pin - Input
    PIOA->PIO_PDR |= PIO_PA25;
    PIOA->PIO_ABSR &= ~(PIO_PA25);  // MISO Pin - (A) Peripheral

    PIOA->PIO_OER |= PIO_PA26;      // MOSI Pin - Output
    PIOA->PIO_PDR |= PIO_PA26;
    PIOA->PIO_ABSR &= ~(PIO_PA26);  // MOSI Pin - (A) Peripheral

    PIOA->PIO_OER |= PIO_PA27;      // SCLK Pin - Output
    PIOA->PIO_PDR |= PIO_PA27;
    PIOA->PIO_ABSR &= ~(PIO_PA27);  // SCLK Pin - (A) Peripheral

    PIOA->PIO_OER |= PIO_PA28;      // CS Pin 0 - Output
    PIOA->PIO_PDR |= PIO_PA28;
    PIOA->PIO_ABSR &= ~(PIO_PA28);  // CS Pin 0 - (A) Peripheral
    PIOA->PIO_PUER |= PIO_PA28;

    // Disable the SPI to configure it
    SPI0->SPI_CR |= SPI_CR_SPIDIS;

    // SPI0 Setup --------------
    PMC->PMC_PCER0 = (1 << ID_SPI0);        // Enable SPI0 Clock

    // Master Mode, Fixed Peripheral Mode, Mode fault detection disabled, Fixed peripheral modes
    SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_MODFDIS;

    // Mode and Clock           Clock Freq Calculation
    SPI0->SPI_CSR[0] |= SPI_CSR_NCPHA | (((int8_t)(CLOCK_SPEED / 1000000)) << 8);       // Need to stick clock calculation in byte 2

    // 8 bits per transfer
    SPI0->SPI_CSR[0] |= SPI_CSR_BITS_8_BIT;

    SPI0->SPI_CR |= SPI_CR_SPIEN;           // Enable SPI0

}

uint8_t pixbuf[] = "This is a test!"; // Buffer to be transmitted

void setup_dma()
{
    PMC->PMC_PCER1 |= (1 << (ID_DMAC - 32)); // Turn on DMA Controller Clock (?)

    DMAC->DMAC_EN = 0; // Disable DMA Controller

    DMAC->DMAC_GCFG = DMAC_GCFG_ARB_CFG_ROUND_ROBIN; // Set arbitration method

    DMAC->DMAC_EN = 1; // Enable DMA Controller

    DMAC->DMAC_CHDR = DMAC_CHDR_DIS0; // Disable DMA Channel 0

    DMAC->DMAC_CH_NUM[0].DMAC_SADDR = (uint32_t)pixbuf; // Set src buffer
    DMAC->DMAC_CH_NUM[0].DMAC_DADDR = (uint32_t)&SPI0->SPI_TDR; // Set dst buffer
    DMAC->DMAC_CH_NUM[0].DMAC_DSCR = 0x0;

    DMAC->DMAC_CH_NUM[0].DMAC_CTRLA = DMAC_CTRLA_DST_WIDTH_BYTE | DMAC_CTRLA_SRC_WIDTH_BYTE | DMAC_CTRLA_BTSIZE(0x10); // Set src/dest bit width (8 bits) and set buffer size to 16
    DMAC->DMAC_CH_NUM[0].DMAC_CTRLB = DMAC_CTRLB_DST_INCR_FIXED | DMAC_CTRLB_SRC_INCR_INCREMENTING | DMAC_CTRLB_FC_MEM2PER_DMA_FC | DMAC_CTRLB_DST_DSCR | DMAC_CTRLB_SRC_DSCR | DMAC_CTRLB_FC_MEM2PER_DMA_FC;

    DMAC->DMAC_CH_NUM[0].DMAC_CFG = DMAC_CFG_DST_PER(1) | DMAC_CFG_DST_H2SEL | DMAC_CFG_SOD_ENABLE | DMAC_CFG_AHB_PROT(1) | DMAC_CFG_FIFOCFG_ALAP_CFG; // Configure DMA Controller

    DMAC->DMAC_EBCISR; // Read interrupt register to clear interrupt flags

    DMAC->DMAC_CHER = DMAC_CHER_ENA0; // Enable DMA Channel 0
}

int main(void)
{
    /* Initialize the SAM system */
    SystemInit();

    setup_dma();
    setup_spi();
    while (!(DMAC->DMAC_CHSR & DMAC_CHSR_ENA0 << 0));
    uint32_t dma_status;

    dma_status = DMAC->DMAC_EBCISR;
    //SPI0->SPI_TDR = 'a'; // Write dummy out

    /* Replace with your application code */
    while (1)
    {
    }
}

Hope this helps.


text:
50% duty cycle PWM signal with calculated frequency
#include <PWM.h>
int led = 9;
void setup()
{
  InitTimersSafe();
  Serial.begin(115200);
  Serial.println();
  variable_freq();
  pinMode(A0,INPUT);
}
void variable_freq()
{
   while(true)
 {
   a=analogRead(A0);
   float p = (a/1024)*5;
   int Vi = p/0.143;
   float Vo = 12;
   float Po=100;
   float n=1, ni=0.9, Ntr=1, Vf=0.7, Rf=0.018, rc=0.025, Mvs=0.9;
   float Rl=(Vo*Vo)/Po;
   float fo = 70000;
   float Mv = Vo/Vi;
   float Qo=6;
   float pi = 3.14159;
   float g ;
   g= (1+(2*(Vf/Vo))+((Rf*pi*pi)/4*Rl)+(rc/Rl)*(((pi*pi)/8)-1));
   float Ri=((8*Rl*n*n)/(Ntr*pi*pi))*g;
   float Mvr, MVR, h;
   Mvr=(pi*Ntr)/(2*n*sqrt(2)*g);
   MVR=Mv/(Mvs*Mvr);
   h=(sqrt((pow((ni/MVR), 2))-1))/Qo;
   float f_sw;
   f_sw = ((fo*h)/2) + (sqrt(pow(fo*h,2) + 4*pow(fo,2)))/2;

   SetPinFrequency(led,f_sw);

   float T = 0.5;

   pwmWriteHR(led,T*65536);
 }
}

I am working on a project where I have to find a required frequency from a varying DC input voltage. I am using Arduino Nano to produce a PWM signal of this required freqeuncy.
From the code, once the frequency f_sw is calculated, I have used the setPinFrequency function to set the frequency of pin D9 to f_sw. I want a PWM signal of duty cycle 50% with f_sw as the frequency.
Does pwmWriteHR(led,T*65536) accomplish this? As per this website, pwmWrite()'s 2nd argument is the duty cycle. Given that pwmWriteHR() is just the higher resolution version of pwmWrite(), will this output the signal as per my requirements?
I cannot test this on a board yet, so I simulated it in Proteus, but the frequency of the signal I obtained there does not match, although the duty cycle was 50%.

What frequency are you getting, and what frequency are you expecting?

The frequency calculated for a certain input voltage value is 76 kHz. But I am not even getting 100 Hz.

Can you please print the value f_sw just prior to doing this line: SetPinFrequency(led,f_sw);

@NickGammon https://imgur.com/a/2sRb40c
I modified the code without analogRead() as I didn't have the setup ready.

The image shows the frequency as 76441.25.

@NickGammon Yes, it matches with the manual calculations. My question is whether float T = 0.5; and pwmWriteHR(led,T*65536); are correct for the required waveform that I require.

pwmWriteHR sets the duty cycle and you say yourself that the duty cycle is indeed 50% so that particular function call does not appear to be the problem. But I am not even getting 100 Hz - what are you getting? It is more useful to tell us what you are getting rather than what you are not getting, wouldn't you agree?

Could you give a link to the exact library file you downloaded for this? The page you linked didn't seem to have a download link on it, and often there are lots of copies of Arduino libraries on the Internet, sometimes slightly different from each other.

Let's look at what's possible using the Atmega328P (which is on the Nano).
The timers are really just counters, with the input to the counter being the system clock, possibly after being divided down by a prescaler.
Timers 0 and 2 are 8-bit timers which means they can count to 256 before wrapping around. Timer 1 is a 16-bit timer which means it can count to 65536 before wrapping. The inputs to the timers are zero-relative, so the actual counter limits are 255 (0xFF) and 65535 (0xFFFF).
Your desired frequency of 76441 means the period is 1/76441 seconds, namely 13.082 µs.
With no prescaler, the period of the system clock is 1/16000000, namely 0.0625 µs.
Divide 13.082 by 0.0625 and you get 209.312 which means 209 counts are going to roughly get you the frequency you want.
However then we have to divide by 2 because each time the counter counts up we toggle the output, and it takes two toggles to do one period (one up, one down).
So we need to set up a timer of 209/2 which is 104.5. Since we can't count up to half a count we actually count up to 104. The code to do that, without needing any libraries, is:

Example code
void setup()
  {
  pinMode (9, OUTPUT);  // output pin is fixed (OC1A)

  unsigned long Hz = 76441;

  // it takes two toggles for one "cycle"
  unsigned long ocr = (F_CPU / Hz / 2) - 1;

  // stop timer
  TCCR1A = 0;
  TCCR1B = 0;
  // reset counter
  TCNT1H = 0;
  TCNT1L = 0;

  // what to count up to
  OCR1AH = highByte (ocr);
  OCR1AL = lowByte (ocr);

  TCCR1A = bit (COM1A0);              // toggle output pin
  TCCR1B = bit (WGM12) | bit (CS10);  // start timer, CTC mode
  }  // end of setup

void loop() { }

The results on pin 9 were measured as 76.805 kHz which is slightly out, partly because of the fact that the resolution is in increments of 62.5 ns, and partly because the Nano has resonator* rather than a crystal, so its clock might not be exactly 16 MHz.
* I'm not sure about that.

Duty cycle
In this particular example we have a 50% duty cycle because each time the timer reaches its count it toggles the output. Thus it does it symmetrically. That is, the on portion will be the same length as the off portion.
There are other timer modes which can be used for PWM generation where the duty cycle is not 50%. See the datasheet for more information.

Prescaler
The prescalers (not used in this particular example) are used to extend the length of time that a timer can count for.
Possible prescalers are 1, 8, 32, 64, 128, 256, and 1024. Prescalers of 32 and 128 are only available on timer 2.
So, for example, if you use a prescaler of 8 then each "tick" of the timer will be 8 * 62.5 ns, so it can count for 8 times as long before it overflows. However each count will only have a resolution of 500 ns rather than 62.5 ns, so you can get a less precise time measurement.
Choosing prescalers is a compromise between resolution and the available time period you can time for.

See my page about timers for more discussion about the Atmega328P timers.

List of possible frequencies
From my page above I reproduce this list which shows what frequency and period you get for various timer counts, and prescalers.
  n  -- Prescale 1   --  -- Prescale 8   --  -- Prescale 64  --  -- Prescale 256 --  -- Prescale 1024--
     Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)
  1: 8,000,000*   0.125  1,000,000    1.000    125,000    8.000     31,250   32.000      7,813  128.000
  2: 5,333,333    0.188    666,667    1.500     83,333   12.000     20,833   48.000      5,208  192.000
  3: 4,000,000    0.250    500,000    2.000     62,500   16.000     15,625   64.000      3,906  256.000
  4: 3,200,000    0.313    400,000    2.500     50,000   20.000     12,500   80.000      3,125  320.000
  5: 2,666,667    0.375    333,333    3.000     41,667   24.000     10,417   96.000      2,604  384.000
  6: 2,285,714    0.438    285,714    3.500     35,714   28.000      8,929  112.000      2,232  448.000
  7: 2,000,000    0.500    250,000    4.000     31,250   32.000      7,813  128.000      1,953  512.000
  8: 1,777,778    0.563    222,222    4.500     27,778   36.000      6,944  144.000      1,736  576.000
  9: 1,600,000    0.625    200,000    5.000     25,000   40.000      6,250  160.000      1,563  640.000
 10: 1,454,545    0.688    181,818    5.500     22,727   44.000      5,682  176.000      1,420  704.000
 11: 1,333,333    0.750    166,667    6.000     20,833   48.000      5,208  192.000      1,302  768.000
 12: 1,230,769    0.813    153,846    6.500     19,231   52.000      4,808  208.000      1,202  832.000
 13: 1,142,857    0.875    142,857    7.000     17,857   56.000      4,464  224.000      1,116  896.000
 14: 1,066,667    0.937    133,333    7.500     16,667   60.000      4,167  240.000      1,042  960.000
 15: 1,000,000    1.000    125,000    8.000     15,625   64.000      3,906  256.000        977 1024.000
 16:   941,176    1.063    117,647    8.500     14,706   68.000      3,676  272.000        919 1088.000
 17:   888,889    1.125    111,111    9.000     13,889   72.000      3,472  288.000        868 1152.000
 18:   842,105    1.187    105,263    9.500     13,158   76.000      3,289  304.000        822 1216.000
 19:   800,000    1.250    100,000   10.000     12,500   80.000      3,125  320.000        781 1280.000
 20:   761,905    1.313     95,238   10.500     11,905   84.000      2,976  336.000        744 1344.000
 21:   727,273    1.375     90,909   11.000     11,364   88.000      2,841  352.000        710 1408.000
 22:   695,652    1.438     86,957   11.500     10,870   92.000      2,717  368.000        679 1472.000
 23:   666,667    1.500     83,333   12.000     10,417   96.000      2,604  384.000        651 1536.000
 24:   640,000    1.562     80,000   12.500     10,000  100.000      2,500  400.000        625 1600.000
 25:   615,385    1.625     76,923   13.000      9,615  104.000      2,404  416.000        601 1664.000
 26:   592,593    1.688     74,074   13.500      9,259  108.000      2,315  432.000        579 1728.000
 27:   571,429    1.750     71,429   14.000      8,929  112.000      2,232  448.000        558 1792.000
 28:   551,724    1.813     68,966   14.500      8,621  116.000      2,155  464.000        539 1856.000
 29:   533,333    1.875     66,667   15.000      8,333  120.000      2,083  480.000        521 1920.000
 30:   516,129    1.938     64,516   15.500      8,065  124.000      2,016  496.000        504 1984.000
 31:   500,000    2.000     62,500   16.000      7,813  128.000      1,953  512.000        488 2048.000
 32:   484,848    2.062     60,606   16.500      7,576  132.000      1,894  528.000        473 2112.000
 33:   470,588    2.125     58,824   17.000      7,353  136.000      1,838  544.000        460 2176.000
 34:   457,143    2.188     57,143   17.500      7,143  140.000      1,786  560.000        446 2240.000
 35:   444,444    2.250     55,556   18.000      6,944  144.000      1,736  576.000        434 2304.000
 36:   432,432    2.313     54,054   18.500      6,757  148.000      1,689  592.000        422 2368.000
 37:   421,053    2.375     52,632   19.000      6,579  152.000      1,645  608.000        411 2432.000
 38:   410,256    2.438     51,282   19.500      6,410  156.000      1,603  624.000        401 2496.000
 39:   400,000    2.500     50,000   20.000      6,250  160.000      1,563  640.000        391 2560.000
 40:   390,244    2.563     48,780   20.500      6,098  164.000      1,524  656.000        381 2624.000
 41:   380,952    2.625     47,619   21.000      5,952  168.000      1,488  672.000        372 2688.000
 42:   372,093    2.687     46,512   21.500      5,814  172.000      1,453  688.000        363 2752.000
 43:   363,636    2.750     45,455   22.000      5,682  176.000      1,420  704.000        355 2816.000
 44:   355,556    2.812     44,444   22.500      5,556  180.000      1,389  720.000        347 2880.000
 45:   347,826    2.875     43,478   23.000      5,435  184.000      1,359  736.000        340 2944.000
 46:   340,426    2.938     42,553   23.500      5,319  188.000      1,330  752.000        332 3008.000
 47:   333,333    3.000     41,667   24.000      5,208  192.000      1,302  768.000        326 3072.000
 48:   326,531    3.063     40,816   24.500      5,102  196.000      1,276  784.000        319 3136.000
 49:   320,000    3.125     40,000   25.000      5,000  200.000      1,250  800.000        313 3200.000
 50:   313,725    3.188     39,216   25.500      4,902  204.000      1,225  816.000        306 3264.000
 51:   307,692    3.250     38,462   26.000      4,808  208.000      1,202  832.000        300 3328.000
 52:   301,887    3.313     37,736   26.500      4,717  212.000      1,179  848.000        295 3392.000
 53:   296,296    3.375     37,037   27.000      4,630  216.000      1,157  864.000        289 3456.000
 54:   290,909    3.437     36,364   27.500      4,545  220.000      1,136  880.000        284 3520.000
 55:   285,714    3.500     35,714   28.000      4,464  224.000      1,116  896.000        279 3584.000
 56:   280,702    3.562     35,088   28.500      4,386  228.000      1,096  912.000        274 3648.000
 57:   275,862    3.625     34,483   29.000      4,310  232.000      1,078  928.000        269 3712.000
 58:   271,186    3.688     33,898   29.500      4,237  236.000      1,059  944.000        265 3776.000
 59:   266,667    3.750     33,333   30.000      4,167  240.000      1,042  960.000        260 3840.000
 60:   262,295    3.813     32,787   30.500      4,098  244.000      1,025  976.000        256 3904.000
 61:   258,065    3.875     32,258   31.000      4,032  248.000      1,008  992.000        252 3968.000
 62:   253,968    3.938     31,746   31.500      3,968  252.000        992 1008.000        248 4032.000
 63:   250,000    4.000     31,250   32.000      3,906  256.000        977 1024.000        244 4096.000
 64:   246,154    4.063     30,769   32.500      3,846  260.000        962 1040.000        240 4160.000
 65:   242,424    4.125     30,303   33.000      3,788  264.000        947 1056.000        237 4224.000
 66:   238,806    4.188     29,851   33.500      3,731  268.000        933 1072.000        233 4288.000
 67:   235,294    4.250     29,412   34.000      3,676  272.000        919 1088.000        230 4352.000
 68:   231,884    4.313     28,986   34.500      3,623  276.000        906 1104.000        226 4416.000
 69:   228,571    4.375     28,571   35.000      3,571  280.000        893 1120.000        223 4480.000
 70:   225,352    4.437     28,169   35.500      3,521  284.000        880 1136.000        220 4544.000
 71:   222,222    4.500     27,778   36.000      3,472  288.000        868 1152.000        217 4608.000
 72:   219,178    4.563     27,397   36.500      3,425  292.000        856 1168.000        214 4672.000
 73:   216,216    4.625     27,027   37.000      3,378  296.000        845 1184.000        211 4736.000
 74:   213,333    4.688     26,667   37.500      3,333  300.000        833 1200.000        208 4800.000
 75:   210,526    4.750     26,316   38.000      3,289  304.000        822 1216.000        206 4864.000
 76:   207,792    4.813     25,974   38.500      3,247  308.000        812 1232.000        203 4928.000
 77:   205,128    4.875     25,641   39.000      3,205  312.000        801 1248.000        200 4992.000
 78:   202,532    4.938     25,316   39.500      3,165  316.000        791 1264.000        198 5056.000
 79:   200,000    5.000     25,000   40.000      3,125  320.000        781 1280.000        195 5120.000
 80:   197,531    5.062     24,691   40.500      3,086  324.000        772 1296.000        193 5184.000
 81:   195,122    5.125     24,390   41.000      3,049  328.000        762 1312.000        191 5248.000
 82:   192,771    5.188     24,096   41.500      3,012  332.000        753 1328.000        188 5312.000
 83:   190,476    5.250     23,810   42.000      2,976  336.000        744 1344.000        186 5376.000
 84:   188,235    5.312     23,529   42.500      2,941  340.000        735 1360.000        184 5440.000
 85:   186,047    5.375     23,256   43.000      2,907  344.000        727 1376.000        182 5504.000
 86:   183,908    5.438     22,989   43.500      2,874  348.000        718 1392.000        180 5568.000
 87:   181,818    5.500     22,727   44.000      2,841  352.000        710 1408.000        178 5632.000
 88:   179,775    5.563     22,472   44.500      2,809  356.000        702 1424.000        176 5696.000
 89:   177,778    5.625     22,222   45.000      2,778  360.000        694 1440.000        174 5760.000
 90:   175,824    5.687     21,978   45.500      2,747  364.000        687 1456.000        172 5824.000
 91:   173,913    5.750     21,739   46.000      2,717  368.000        679 1472.000        170 5888.000
 92:   172,043    5.813     21,505   46.500      2,688  372.000        672 1488.000        168 5952.000
 93:   170,213    5.875     21,277   47.000      2,660  376.000        665 1504.000        166 6016.000
 94:   168,421    5.937     21,053   47.500      2,632  380.000        658 1520.000        164 6080.000
 95:   166,667    6.000     20,833   48.000      2,604  384.000        651 1536.000        163 6144.000
 96:   164,948    6.063     20,619   48.500      2,577  388.000        644 1552.000        161 6208.000
 97:   163,265    6.125     20,408   49.000      2,551  392.000        638 1568.000        159 6272.000
 98:   161,616    6.188     20,202   49.500      2,525  396.000        631 1584.000        158 6336.000
 99:   160,000    6.250     20,000   50.000      2,500  400.000        625 1600.000        156 6400.000
100:   158,416    6.313     19,802   50.500      2,475  404.000        619 1616.000        155 6464.000
101:   156,863    6.375     19,608   51.000      2,451  408.000        613 1632.000        153 6528.000
102:   155,340    6.438     19,417   51.500      2,427  412.000        607 1648.000        152 6592.000
103:   153,846    6.500     19,231   52.000      2,404  416.000        601 1664.000        150 6656.000
104:   152,381    6.562     19,048   52.500      2,381  420.000        595 1680.000        149 6720.000
105:   150,943    6.625     18,868   53.000      2,358  424.000        590 1696.000        147 6784.000
106:   149,533    6.688     18,692   53.500      2,336  428.000        584 1712.000        146 6848.000
107:   148,148    6.750     18,519   54.000      2,315  432.000        579 1728.000        145 6912.000
108:   146,789    6.813     18,349   54.500      2,294  436.000        573 1744.000        143 6976.000
109:   145,455    6.875     18,182   55.000      2,273  440.000        568 1760.000        142 7040.000
110:   144,144    6.938     18,018   55.500      2,252  444.000        563 1776.000        141 7104.000
111:   142,857    7.000     17,857   56.000      2,232  448.000        558 1792.000        140 7168.000
112:   141,593    7.063     17,699   56.500      2,212  452.000        553 1808.000        138 7232.000
113:   140,351    7.125     17,544   57.000      2,193  456.000        548 1824.000        137 7296.000
114:   139,130    7.187     17,391   57.500      2,174  460.000        543 1840.000        136 7360.000
115:   137,931    7.250     17,241   58.000      2,155  464.000        539 1856.000        135 7424.000
116:   136,752    7.313     17,094   58.500      2,137  468.000        534 1872.000        134 7488.000
117:   135,593    7.375     16,949   59.000      2,119  472.000        530 1888.000        132 7552.000
118:   134,454    7.437     16,807   59.500      2,101  476.000        525 1904.000        131 7616.000
119:   133,333    7.500     16,667   60.000      2,083  480.000        521 1920.000        130 7680.000
120:   132,231    7.563     16,529   60.500      2,066  484.000        517 1936.000        129 7744.000
121:   131,148    7.625     16,393   61.000      2,049  488.000        512 1952.000        128 7808.000
122:   130,081    7.687     16,260   61.500      2,033  492.000        508 1968.000        127 7872.000
123:   129,032    7.750     16,129   62.000      2,016  496.000        504 1984.000        126 7936.000
124:   128,000    7.813     16,000   62.500      2,000  500.000        500 2000.000        125 8000.000
125:   126,984    7.875     15,873   63.000      1,984  504.000        496 2016.000        124 8064.000
126:   125,984    7.938     15,748   63.500      1,969  508.000        492 2032.000        123 8128.000
127:   125,000    8.000     15,625   64.000      1,953  512.000        488 2048.000        122 8192.000
128:   124,031    8.063     15,504   64.500      1,938  516.000        484 2064.000        121 8256.000
129:   123,077    8.125     15,385   65.000      1,923  520.000        481 2080.000        120 8320.000
130:   122,137    8.188     15,267   65.500      1,908  524.000        477 2096.000        119 8384.000
131:   121,212    8.250     15,152   66.000      1,894  528.000        473 2112.000        118 8448.000
132:   120,301    8.313     15,038   66.500      1,880  532.000        470 2128.000        117 8512.000
133:   119,403    8.375     14,925   67.000      1,866  536.000        466 2144.000        117 8576.000
134:   118,519    8.438     14,815   67.500      1,852  540.000        463 2160.000        116 8640.000
135:   117,647    8.500     14,706   68.000      1,838  544.000        460 2176.000        115 8704.000
136:   116,788    8.563     14,599   68.500      1,825  548.000        456 2192.000        114 8768.000
137:   115,942    8.625     14,493   69.000      1,812  552.000        453 2208.000        113 8832.000
138:   115,108    8.688     14,388   69.500      1,799  556.000        450 2224.000        112 8896.000
139:   114,286    8.750     14,286   70.000      1,786  560.000        446 2240.000        112 8960.000
140:   113,475    8.812     14,184   70.500      1,773  564.000        443 2256.000        111 9024.000
141:   112,676    8.875     14,085   71.000      1,761  568.000        440 2272.000        110 9088.000
142:   111,888    8.938     13,986   71.500      1,748  572.000        437 2288.000        109 9152.000
143:   111,111    9.000     13,889   72.000      1,736  576.000        434 2304.000        109 9216.000
144:   110,345    9.063     13,793   72.500      1,724  580.000        431 2320.000        108 9280.000
145:   109,589    9.125     13,699   73.000      1,712  584.000        428 2336.000        107 9344.000
146:   108,844    9.188     13,605   73.500      1,701  588.000        425 2352.000        106 9408.000
147:   108,108    9.250     13,514   74.000      1,689  592.000        422 2368.000        106 9472.000
148:   107,383    9.313     13,423   74.500      1,678  596.000        419 2384.000        105 9536.000
149:   106,667    9.375     13,333   75.000      1,667  600.000        417 2400.000        104 9600.000
150:   105,960    9.437     13,245   75.500      1,656  604.000        414 2416.000        103 9664.000
151:   105,263    9.500     13,158   76.000      1,645  608.000        411 2432.000        103 9728.000
152:   104,575    9.563     13,072   76.500      1,634  612.000        408 2448.000        102 9792.000
153:   103,896    9.625     12,987   77.000      1,623  616.000        406 2464.000        101 9856.000
154:   103,226    9.688     12,903   77.500      1,613  620.000        403 2480.000        101 9920.000
155:   102,564    9.750     12,821   78.000      1,603  624.000        401 2496.000        100 9984.000
156:   101,911    9.813     12,739   78.500      1,592  628.000        398 2512.000        100 10048.000
157:   101,266    9.875     12,658   79.000      1,582  632.000        396 2528.000         99 10112.000
158:   100,629    9.938     12,579   79.500      1,572  636.000        393 2544.000         98 10176.000
159:   100,000   10.000     12,500   80.000      1,563  640.000        391 2560.000         98 10240.000
160:    99,379   10.062     12,422   80.500      1,553  644.000        388 2576.000         97 10304.000
161:    98,765   10.125     12,346   81.000      1,543  648.000        386 2592.000         96 10368.000
162:    98,160   10.188     12,270   81.500      1,534  652.000        383 2608.000         96 10432.000
163:    97,561   10.250     12,195   82.000      1,524  656.000        381 2624.000         95 10496.000
164:    96,970   10.313     12,121   82.500      1,515  660.000        379 2640.000         95 10560.000
165:    96,386   10.375     12,048   83.000      1,506  664.000        377 2656.000         94 10624.000
166:    95,808   10.438     11,976   83.500      1,497  668.000        374 2672.000         94 10688.000
167:    95,238   10.500     11,905   84.000      1,488  672.000        372 2688.000         93 10752.000
168:    94,675   10.563     11,834   84.500      1,479  676.000        370 2704.000         92 10816.000
169:    94,118   10.625     11,765   85.000      1,471  680.000        368 2720.000         92 10880.000
170:    93,567   10.687     11,696   85.500      1,462  684.000        365 2736.000         91 10944.000
171:    93,023   10.750     11,628   86.000      1,453  688.000        363 2752.000         91 11008.000
172:    92,486   10.813     11,561   86.500      1,445  692.000        361 2768.000         90 11072.000
173:    91,954   10.875     11,494   87.000      1,437  696.000        359 2784.000         90 11136.000
174:    91,429   10.938     11,429   87.500      1,429  700.000        357 2800.000         89 11200.000
175:    90,909   11.000     11,364   88.000      1,420  704.000        355 2816.000         89 11264.000
176:    90,395   11.063     11,299   88.500      1,412  708.000        353 2832.000         88 11328.000
177:    89,888   11.125     11,236   89.000      1,404  712.000        351 2848.000         88 11392.000
178:    89,385   11.188     11,173   89.500      1,397  716.000        349 2864.000         87 11456.000
179:    88,889   11.250     11,111   90.000      1,389  720.000        347 2880.000         87 11520.000
180:    88,398   11.312     11,050   90.500      1,381  724.000        345 2896.000         86 11584.000
181:    87,912   11.375     10,989   91.000      1,374  728.000        343 2912.000         86 11648.000
182:    87,432   11.438     10,929   91.500      1,366  732.000        342 2928.000         85 11712.000
183:    86,957   11.500     10,870   92.000      1,359  736.000        340 2944.000         85 11776.000
184:    86,486   11.563     10,811   92.500      1,351  740.000        338 2960.000         84 11840.000
185:    86,022   11.625     10,753   93.000      1,344  744.000        336 2976.000         84 11904.000
186:    85,561   11.688     10,695   93.500      1,337  748.000        334 2992.000         84 11968.000
187:    85,106   11.750     10,638   94.000      1,330  752.000        332 3008.000         83 12032.000
188:    84,656   11.813     10,582   94.500      1,323  756.000        331 3024.000         83 12096.000
189:    84,211   11.875     10,526   95.000      1,316  760.000        329 3040.000         82 12160.000
190:    83,770   11.937     10,471   95.500      1,309  764.000        327 3056.000         82 12224.000
191:    83,333   12.000     10,417   96.000      1,302  768.000        326 3072.000         81 12288.000
192:    82,902   12.063     10,363   96.500      1,295  772.000        324 3088.000         81 12352.000
193:    82,474   12.125     10,309   97.000      1,289  776.000        322 3104.000         81 12416.000
194:    82,051   12.188     10,256   97.500      1,282  780.000        321 3120.000         80 12480.000
195:    81,633   12.250     10,204   98.000      1,276  784.000        319 3136.000         80 12544.000
196:    81,218   12.313     10,152   98.500      1,269  788.000        317 3152.000         79 12608.000
197:    80,808   12.375     10,101   99.000      1,263  792.000        316 3168.000         79 12672.000
198:    80,402   12.437     10,050   99.500      1,256  796.000        314 3184.000         79 12736.000
199:    80,000   12.500     10,000  100.000      1,250  800.000        313 3200.000         78 12800.000
200:    79,602   12.562      9,950  100.500      1,244  804.000        311 3216.000         78 12864.000
201:    79,208   12.625      9,901  101.000      1,238  808.000        309 3232.000         77 12928.000
202:    78,818   12.688      9,852  101.500      1,232  812.000        308 3248.000         77 12992.000
203:    78,431   12.750      9,804  102.000      1,225  816.000        306 3264.000         77 13056.000
204:    78,049   12.813      9,756  102.500      1,220  820.000        305 3280.000         76 13120.000
205:    77,670   12.875      9,709  103.000      1,214  824.000        303 3296.000         76 13184.000
206:    77,295   12.938      9,662  103.500      1,208  828.000        302 3312.000         75 13248.000
207:    76,923   13.000      9,615  104.000      1,202  832.000        300 3328.000         75 13312.000
208:    76,555   13.062      9,569  104.500      1,196  836.000        299 3344.000         75 13376.000
209:    76,190   13.125      9,524  105.000      1,190  840.000        298 3360.000         74 13440.000
210:    75,829   13.187      9,479  105.500      1,185  844.000        296 3376.000         74 13504.000
211:    75,472   13.250      9,434  106.000      1,179  848.000        295 3392.000         74 13568.000
212:    75,117   13.313      9,390  106.500      1,174  852.000        293 3408.000         73 13632.000
213:    74,766   13.375      9,346  107.000      1,168  856.000        292 3424.000         73 13696.000
214:    74,419   13.438      9,302  107.500      1,163  860.000        291 3440.000         73 13760.000
215:    74,074   13.500      9,259  108.000      1,157  864.000        289 3456.000         72 13824.000
216:    73,733   13.563      9,217  108.500      1,152  868.000        288 3472.000         72 13888.000
217:    73,394   13.625      9,174  109.000      1,147  872.000        287 3488.000         72 13952.000
218:    73,059   13.687      9,132  109.500      1,142  876.000        285 3504.000         71 14016.000
219:    72,727   13.750      9,091  110.000      1,136  880.000        284 3520.000         71 14080.000
220:    72,398   13.812      9,050  110.500      1,131  884.000        283 3536.000         71 14144.000

* = may not work reliably, testing shows.
Space restraints preclude including the entire list, see the page mentioned above for a few more rows.


text:
Arduino Nano not receiving MIDI messages
so I am currently creating a MIDI to CV module and am still having trouble with my MIDI input circuit. I am following this circuit as my guideline and am sending MIDI messages via MIDI interface with the use of this cable. I am also using this software called MIDIKeys as a virtual keyboard for the MIDI notes. Unfortunately, every time I play a note on the keyboard the Arduino doesn't respond with the blink of the LED. I could really use some guidance on fixing this problem.
Below is also the code that I'm using:
#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

//Create an instance of the library with default name, serial port and settings
//MIDI_CREATE_DEFAULT_INSTANCE();
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
  MIDI.turnThruOff();
  MIDI.setHandleNoteOn(MyHandleNoteOn);
  MIDI.setHandleNoteOff(MyHandleNoteOff);
  Serial.begin(31250);
}

void loop() { // Main loop
  MIDI.read(); // Continuously check if Midi data has been received.
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,LOW);  //Turn LED off
}

Edit:
To verify that my laptop is sending a MIDI message I am using this MIDI Monitor

how do you know that the PC is sending NoteOn events? ... please edit your question with a description of what you already tried

I doubt that the virtual keyboard sends serial messages to the com port


text:
Serial does not receive all chars
I'm trying to follow Serial Input Basics to build a program which receives commands over serial like "<led:12,34,21>" but i'm stuck on receiving the characters from serial...
I have copied the code from the example for receiveWithStartAndEndMarkers but it does not show that i received all the characters over serial
const int kMaxCommandSize=30;
char receivedChars[kMaxCommandSize + 1];
char command[kMaxCommandSize + 1];
boolean newData = false;

void setup() {
  Serial.begin(115200);
}

void loop() {
  recvWithStartEndMarkers();
  if(newData){
    ProcessCommand();
    newData = false;
  }
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

 // if (Serial.available() > 0) {
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= kMaxCommandSize) {
                    ndx = kMaxCommandSize - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        } else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void ProcessCommand() {
  Serial.println("Received:");
  Serial.println(receivedChars);
}

But when i send <123> i am consistently seeding
Received:
1
Received:
1
Received:
1

or when i send <asdf1234> i see
Received:
a
Received:
a
Received:
a

EDIT: it looks like sometimes the full transmission works... But not often i just sent <123> four times and got
Received:
123
Received:
12
Received:
1
Received:
123

Your provided sketch is not complete and does not compile, how and where is kMaxCommandSize defined? -- OT: I love this safe comparisons for booleans, you should make sure that it really works: (newData == false) == true. ;-) Hint: if it does not read nice, consider to rename the variable, for example to hasNewData.

I can't reproduce that. On my Uno, with the added line const int kMaxCommandSize = 32; it works perfectly.

Which Arduino are you testing it on?

@thebusybee sorry, kMaxCommandSize can be replaced by 30

@NickGammon I tried on a Mega (where the issue originally occurred), and a Uno. On the Uno it doesnt even reply! Its like the messages go no where.... Maybe both of them are bad...

You may try a simpler program that just echoes whatever it receives: void loop(){if(Serial.available())Serial.write(Serial.read());}. If it's still unreliable, look at the TX and RX pins with an oscilloscope.


text:
Troubleshoot/Diagnose Arduino circuit
I've built the attached circuit with the following changes:

I used Arduino Nano
I used 10K pot
12V is connected to VIN pin (instead of RAW)
the Arduino was connected to the PC by USB for the use of serial communication.

I used 12V 4Pin fan (C25704-002)
Here is the code, I used:
    const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
   // Configure Timer 1 for PWM @ 25 kHz.
    TCCR1A = 0;           // undo the configuration done by...
    TCCR1B = 0;           // ...the Arduino core library
    TCNT1  = 0;           // reset timer
    TCCR1A = _BV(COM1A1)  // non-inverted PWM on ch. A
           | _BV(COM1B1)  // same on ch; B
           | _BV(WGM11);  // mode 10: ph. correct PWM, TOP = ICR1
    TCCR1B = _BV(WGM13)   // ditto
           | _BV(CS10);   // prescaler = 1
    ICR1   = 320;         // TOP = 320

    // Set the PWM pins as output.
    pinMode( 10, OUTPUT);

}

// PWM output @ 25 kHz, only on pins 9 and 10.
// Output value should be between 0 and 320, inclusive.
void analogWrite25k(int value)
{

    OCR1A = value;

}

void loop() {
    // read the analog in value:
    sensorValue = analogRead(analogInPin);

    // map it to the range of the analog out:
    outputValue = map(sensorValue, 0, 1023, 0, 320);

    analogWrite25k(outputValue);

I have the following questions:

The circuit was working for couple of minutes but then I smelled the famous electronic components barbecue smell, so I disconnected the GND power line and when I did I felt that the GND line was hot, I think I fried the Arduino, Do you have an idea what can fry the Arduino?
The Potentiometer (10K) was not sensitive, It worked only on some range of the knob, What resistance should I use?

Thanks.

you connected 12 V to A0


text:
Problem changing the state of the blue LED on an ESP8266
I am trying to change the blue LED on my ESP8266. I can do this (sort of...)
In the setupWifi() function below, there is a loop that is supposed to rapidly blink the LED while wifi is connecting.  The only way I can flash the blue light is if the print statement (Serial.print(".");) is present.  If I remove this (and even increase the delay) the blue light will not flash.  If the print statement is present, it works as expected.
The other issue I have is when I click the web page to turn the light on or off.  The values print correctly, but the LED only blinks briefly on in both cases.
My questions are:

Why am I only able to change the led when there is a print statement in the loop while waiting for wifi connectivity?
Why am I unable to change the led in the main loop?

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>

#define SECONDS_PER_MINUTE 60
#define SECONDS_PER_HOUR 60 * SECONDS_PER_MINUTE
#define SECONDS_PER_DAY 24 * SECONDS_PER_HOUR
#define SECONDS_PER_WEEK 7 * SECONDS_PER_DAY

#define LED_PIN 1
#define TIME_UPDATE SECONDS_PER_WEEK

const char* ssid = "ssid";
const char* password = "password";
const char* hostname = "hostname";

const long utcOffsetInSeconds = -4 * SECONDS_PER_HOUR;

SoftwareSerial ESPserial(2, 3); // RX | TX
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
ESP8266WebServer server(80);

uint8_t ledStatus = LOW;
uint8_t lastLedStatus = ledStatus;
unsigned long lastUpdate = 0;

void updateTime() {
  time_t epochTime = timeClient.getEpochTime();

  if (epochTime > lastUpdate + TIME_UPDATE) {
    Serial.println("Syncing time with server");
    timeClient.update();
    time_t epochTime = timeClient.getEpochTime();
    struct tm *ptm = gmtime ((time_t *)&epochTime);

    int hour = timeClient.getHours();
    int minute = timeClient.getMinutes();
    int second = timeClient.getSeconds();
    int day = ptm->tm_mday;
    int month = ptm->tm_mon+1;
    int year = ptm->tm_year+1900;

    Serial.printf("Time synched at: %d/%d/%d %d:%d:%d\n", day, month, year, hour, minute, second);
    lastUpdate = epochTime;
  }
}

void setupSerial() {
  Serial.begin(9600);
  ESPserial.begin(115200);
  ESPserial.println("AT+IPR=9600");
  delay(1000);
  ESPserial.end();
  ESPserial.begin(9600);
  Serial.println("Serial Port Initialized");
  ESPserial.println("AT+GMR");
}

void setupWifi() {
  bool ledState = HIGH;
  Serial.println("Connecting to WIFI");

  WiFi.mode(WIFI_STA);
  WiFi.hostname(hostname);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
    digitalWrite(LED_PIN, ledState);
    ledState = !ledState;
  }

  Serial.println("WIFI connected");
  Serial.println(WiFi.localIP());
}

void setup() {
  pinMode(LED_PIN, OUTPUT);
  timeClient.begin();
  setupSerial();
  setupWifi();
  delay(100);

  server.on("/", handleOnConnect);
  server.on("/led1on", handleLedOn);
  server.on("/led1off", handleLedOff);
  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  updateTime();
  server.handleClient();

  if (lastLedStatus != ledStatus) {
    Serial.printf("Writing %u\n", ledStatus);
    digitalWrite(LED_PIN, ledStatus);
    lastLedStatus = ledStatus;
  }
}

void handleOnConnect()  {
  server.send(200, "text/html", SendHTML(ledStatus));
}

void handleLedOn() {
  ledStatus = HIGH;
  Serial.printf("Turning LED: %u\n", ledStatus);
  // digitalWrite(LED_PIN, ledStatus);
  server.send(200, "text/html", SendHTML(ledStatus));
}

void handleLedOff() {
  ledStatus = LOW;
  Serial.printf("Turning LED: %u\n", ledStatus);
  // digitalWrite(LED_PIN, ledStatus);
  server.send(200, "text/html", SendHTML(ledStatus));
}

void handleNotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t ledStatus){
  String ptr = "<!DOCTYPE html> \n";
  ptr +="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="\n";
  ptr +="\n";
  ptr +="\n";
  ptr +="
ESP8266 Web Server
\n";
  ptr +="
Using Access Point(AP) Mode
\n";

   if(ledStatus
  )
  {ptr +="
LED1 Status: ON
OFF\n";}
  else
  {ptr +="
LED1 Status: OFF
ON\n";}

  ptr +="\n";
  ptr +="\n";
  return ptr;
}

what do you want to know?

Why does the first case require a println and why doesn't the second case turn the led on and off at all (other than a brief flash when turning it on or off - which could even be the webserver)

your question belongs in your post, not is a comment ... this site is not a forum where you chat back and forth ... all of your question should be in one place

Do you know for sure that the LED is meant to be controllable? Pin 1 is the serial transmit pin, so I’d guess that the LED is really meant to indicate activity on the serial port.

I have read that changing it is possible and have been successful at doing so under the right conditions.  Your question is very valid and I didn't realize that they shared the same pin.  I'll give this a shot with an external LED, but I was hoping to use the built-in one for diagnostics :-/

calling Serial.print changes the pin_mode of pin1 to special. if you call pinMode before digitalWrite (or don't call print) it will work each time.


text:
GPS module NEO M8M not responding with Atmega 328P
I designed PCb for relay Switching using gps signal for that i am using atmaga 328P-AU and Neo 6M but after connecting gps module its not showing long, lat. i also checked power supply in module pin it shows 4.96V and RX, TX connection are also properly soldered.
i tested simple code to see the uart data in module and it should be something regardless of satelite connection but it shows nothing.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); //(RX, TX) check correct pin assignments.

void setup() {

mySerial.begin(9600);

Serial.begin(9600);

Serial.println("GPS start");

}

void loop() {

while (mySerial.available()) {

Serial.write(
mySerial.read());

}

}

in serial monitor it only shows "GPS start" when i press reset button
Schematic

my pcb layout

Actual PCB

So far i have tried this things but didnt get any result.
1.swapping RX,TX pins.
2.changing GPS module.
3.kept gps module in balcony for more than 4 hours.
4.connection checked more than 10 times.

is the GPS module oriented correctly in the plug?

also posted at https://electronics.stackexchange.com/questions/667300/gps-module-neo-m8m-not-responding-with-atmega-328p

yes it is oriented correctly