text:
Do these types of wires exist?
I was wondering if the following type of wire adapter existed. Because I have some small JST pins and I need to connect them to some JST XH pins. (Preferably on amazon):

JST to JST XH adapter

JST What to JST XH?

I can do PH to XH custom cables.

@jsotola Looks like it's been spliced from two images.

@Majenko you are right ... i was seeing heatshrink tubing ... my apologies to the OP

@jsotola That's what I thought at first too.

@DigitalRookie4 what's the application? ... what is preventing you from buying the two different connectors with pigtails and splicing the pigtails?

@jsotola I am not an expert on all things to do with "splicing the pigtails". In addition to this, the picture was edited and the reason why the wires were different sizes was just because I was just trying to get the idea of what I was wanting across. What I am asking is that do these types of wires exist.

@Majenko I don't know how to really describe it. A small JST to a large JST?

Every type of JST connector has a code made from a combination of letters. One end of that is XH. The other end is unknown. You need to know what the JST code is for that end. Then you can google for it.

@Majenko I have just had a look and I think the small wire is a ZH JST.

You can buy both XH and ZH cables on eBay. Just get both and connect them together.

@DigitalRookie4 all you need is some heatshrink tubing, a cigarette lighter and diagonal cutters (or strong fingernails) ... wirestrippers would work, but are more specialized ... strip the two wire ends, twist together, slide on heatshrink tubing and shrink using a cigarette lighter ... no soldering required

@jsotola I have a soldering kit somewhere (I think). I have not used it before, how about I use that to solder the 2 wires together?

if you apply solder to the connection, then it becomes brittle and breaks easily, unless the wire does not get moved after installation

https://www.instructables.com/Master-a-perfect-inline-wire-splice-everytime/

@jsotola That's perfect! However one wire is quite small in diameter and one is larger in diameter. Will this still work? I have wiring tape which might work instead of "headshrink tubing". Why would I need some sort of lighter to do it?

Yep sorry, that must have been a typo, you know what I mean. What is the answer to the question above?

@jsotola I have tried it out with a spare wire and it seemed to work very well

heatshrink tubing shrinks about 50% in diameter when heated ... a butane cigarette lighter is the easiest tool to use ... electrical tape tends to become gummy and peels off ... heatshrink tubing grips the wire insulation tightly and becomes a good strain relief for the connectionby keeping it together and maintaining flexibility


text:
9 volt battery not being able to power motor driver
Currently I am using a 9 Volt Duracell A one like this:

I am using it to power a motor driver which contains 2 motors within. I  can see where the main problem is coming and that is to do with that the voltage is not big enough. But I don't understand why this is. I see in the manual for the robot that I am building it is using a smaller voltage battery than what I am using. I tried using another set of batteries but the motors did not move at all then. The 9V Duracell battery that I am currently using has only been used for about a week (so it probably hasn't ran out), its practically brand new.

Voltage is not the be all and end all. Power density and current delivery are more important, and PP3 batteries fail at both.

that battery contains six AAAA cells ... think about the difference between AA and AAA

This question has been asked several times on this site. A quick search gave me  this question and this question. Both explain, that 9V block cells are not up to the job of driving motors

It is likely not a question of the voltage being "big enough". You do need to feed the correct voltage to your robot, but max current and capacity are also very important.
Those "9V transistor batteries" have very low peak current and very low total power capacity (measured in milliamp-hours, or mAh.) They are not up to the job of powering motors. You could easily drain a 9V battery like that in 15 minutes, much less a week.
You should connect 6 D cells in series, and use that instead. That would give you enough peak current and total capacity for your robot.

Does this mean that I have destroyed my 9V battery

Used it up, more likely. If you have a volt meter, measure the output voltage. If it's much less than 9 volts, the 9V battery is too weak to be useful. Those are disposable, and don't have much "juice" even when they're new. Toss it and get a bigger battery.

Oh dear........

source: Stack Exchange

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

sort: votes


text:
9 volt battery unable to power 2 plastic yellow motors
I am trying to build a robot using a kit I got from amazon:
https://www.amazon.co.uk/DFRobot-Tank-Mobile-Platform/dp/B014L1CF1K?th=1
(it uses plastic motors).
The main problem that I am having is that whenever I try to apply a battery with 9 volts to one of the motors it only moves the slightest amount. I am not sure if the voltage is too low or not because in the manual it is using 7.4 volts.
The motors are connected up to a motor driver, here is a diagram of what it looks like

Could the motors potentially be broken? (Hope not because it means I will have to dissect the whole robot)
The motors I am using look like this:

9V batteries are utter junk.

Could you try to use 2 Li-ion battery (like 18650)? They will give you 7.4 - 8.4V.

@AleksejVasinov Isn't that going to give less voltage than the current battery that I am using though?

In specification it is written - "Working Voltage: 3-8V DC". So you should be good :)

@AleksejVasinov One thing I tried doing was connecting one of the motors up to the 9V battery and this seemed to only nudge the motor forwards slightly (almost nothing). So could this mean its the motor that is faulty?

Good news, I seem to have solved the problem! I found some other batteries and they worked perfectly.

@DigitalRookie4 good news. I wanted to advise you to use tester for checking voltage of you battery. But you were faster :)

9v batteries are incapable of supplying enough current for a motor; their best application is tiny-current, standby devices like smoke detectors. You need a power supply that can deliver much more current than the 9v brick can. 6 AA cells in series would do much better. 6 pairs of AA-cells would give you longer run time (each 2 cells in parallel; the 6 parallel pairs in series). You could accomplish the same thing using AAA-cells if your project values space over run-time.

6 D-sized cells would be better yet. Those provide both a large peak current and a large amount of power (measured in amp/hours.) Those are large and heavy, however.

@DuncanC the robot's width is about 20cm. It could still work though. I might be able to find a way around it

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


text:
Certain componenet does not seen to respond when given voltage
I am using a part off an electronics set I got a long time ago. It is off a electronic set called

snap circuits rover deluxe

Its a disc launcher and I have wired it to how it seems to want to be wired:

The idea is that these circles you can see on the disc launcher are button tops and connect to other with other buttons just like buttons on a coat and how the pop together. I have some special wires that allow these button tops to be connected to arduino wires (which are what I am using).
In terms of a power supply I have connected a 9V power supply (not 9V transistor battery) and I have connected the + wire to the + button on the disc launcher and the same with the - wire being connected to the - button on the disc launcher. The only confusions that I now have are:

What is the CONT button potentially used for?
What is the EXT potentially used for?
I just tried guessing by putting the 9V power supply into the CONT and EXT buttons by using a breadboard, nothing happened from this, and I was also thinking during this where is the ground for the CONT and EXT pins.

If this will not simply work then, I was wondering does anyone know where I can buy an arduino plastic missile launcher

What is the CONT button potentially used for?

That's the trigger. Connect that to (-) and a disc should fire.

What is the EXT potentially used for? I just tried guessing by putting the 9V power supply into the CONT and EXT buttons by using a breadboard, nothing happened from this,

That is for triggering another device when this triggers. With your pop connections it can be hard to connect multiple things to the same signal, so for convenience they have given you a "pass through" connection. You could use that to chain together multiple disc launchers (EXT on one connected to CONT on the other)

and I was also thinking during this where is the ground for the CONT and EXT pins.

The (-) battery connection is ground.

By using the CONT, could you somehow use a digital pin signal to activate the disc launcher?

Majenko, how are you figuring out the disc shooter? Did you find some specs, or are you making educated guesses about how it works? I wonder if it uses 5V CMOS control signals, or if it drives higher voltages through the signal pins? If the CONT line feeds >5V out it would damage an Arduino digital pin when you set the pin to LOW.

@DuncanC There's certain keywords that have special meaning, such as "Active Low" - which means for an input connect it to ground to activate it, or for an output it will go to ground to indicate that it's active. - on the battery is almost always ground. Everything you need is in that image, you just have to know how to interpret what it says.

You need to connect (-) to both the battery - terminal and to the Arduino ground.
Connect CONT to a digital output pin on the Arudino. When you set the Arudino pin to LOW, it should trigger the disc launcher.
If the disc launcher uses CMOS logic you should be good to go. IF it uses TTL logic then you will need a TTL driver chip or a transistor or you might burn out the Arduino pin. You will need the specs for the disc launcher to be sure, or measure the current it drives through the CONT pin to ground. (It should be effectively zero for a CMOS pin, since CMOS inputs are capacitive. If it's a TTL input it will push like 20mA from the CONT pin to ground, as I recall.)

The digital pin output did not fully work sorry :( . But I had another idea I could use a transistor to turn the circuit on or off when I want to


text:
Can an Arduino access a network database?
This is a similar question to a previous question I have asked. Primarily I am looking to find out more about the capability of the Arduino.
Here is the scenario. There is a PC that is connected to a database via local network or internet. Is it possible that by plugging an Arduino in the usb port of this PC the Arduino could read from this database by means of an SQL query? Given that the Arduino would have the correct credentials. I am not asking if the Arduino could Hack into the database. I am asking if it is capable of accessing the database at all. Also this must be done without installing any special program on the PC. If that isn't possible, what type of program is needed? I am not necessarily looking for a tutorial, but if you could point me in the right direction that's be great.
Thank you.

What kind of Arduino?

It's actually a Trinket M0. Not Arduino brand, but I can get a different Microcontroller if necessary.

buy an Ethernet or WiFi shield. nobody reads the database over USB and PC

The M0 has a "native" USB interface. Because of that it can be programmed to appear as any kind of device you can image - as long as you can find (or write) the code to do that.
You could (though I have never tried and don't know what code is readily available for this) program the USB interface to be a USB Ethernet device. Your computer would then see it as a new Ethernet interface.
It would then be trivial to "share" your internet connection in Windows with that new Ethernet interface (nothing to install, but settings on the computer need changing), and your Arduino would then be on the network the same as your computer (just as if you'd given it a WiFi interface or something like that). Then it can connect to the database itself (or to a website that communicates with the database if that is simpler) and do whatever it needs to do.
Step one, of course, will be to find a library that will give you that USB Ethernet interface...
A much simpler option, if you're willing to change your M0 for something else, is to use a chip with a built in WiFi interface, such as the ESP32. There's no need for your computer at all then.

TCP/IP over UART is simpler. as null modem connection. there is a library but I don't know if somebody uses it

Thank you for the response

@Juraj You mean SLIP, or PPP? Simpler to program on the Arduino - harder to set up on the PC end.

https://playground.arduino.cc/Code/SerialIP/

@Juraj I rest my case: the Windows instructions (a PDF) no longer exist (good job I speak Swedish...). And there's no DUNS in home versions of windows any more. So a nightmare to set up...


text:
Make the Arduino read data from the PC
I will be brief. There is as windows PC running a program. This program has live updating data on it. Without modifying the PC or adding any programs to the PC, is it possible to program an Arduino to read specific data from this program. In other words the Arduino would be connected to the PC via a USB port and it would need to actively read specific data from this program without having to modify the PC in any way, software or otherwise. I do have access to the PC and can learn almost anything I need to about the program during the development of this system, however in practice, I need the Arduino to simply be plugged into this PC and begin reading its data. Is this possible?  I am not asking for a tutorial however if you could point me in the right direction that would be great.
Thanks

No.  That's not possible.  The Arduino can only receive serial data from the PC over the USB.  Unless there is some program sending the information out on the serial port then Arduino has no access to it.

why would anyone want to use a PC that is so unsecure that it does not even need to be hacked to spill its data

Add a camera to an Arduino, point it at the screen, and have it take a picture. Then use OCR to convert portions of the image to text. Oh, and upgrade your Arduino to a Raspberry Pi so it's physically capable of such actions.

Study the USB stack of your Windows machine. Search for vulnerabilities. Once you find a security hole, program an exploit that lets the Arduino breach into it.

Thanks for the info

@Majenko♦ has given me an idea ... program the arduino to emulate a serial port and a keyboard ... when plugged into the PC, the arduino sends the necessary keystrokes to dump the data to the PC serial port ... of course the difficulty lies in getting the running program data to the serial port on the PC side ... maybe copy and paste

Haha that's not a bad idea

As the comments already stated: No, not possible. For multiple reasons:

USB is a master/slave protocol. The slave (here the Arduino) cannot do anything without the master. It can just expose it's data endpoints and hold data ready to read at these endpoints for the master or wait for data from the master on these endpoints. When the application on the PC is not programmed to speak over USB, you cannot get the data over USB.

Even directly on the PC you cannot simply extract data from a different program. That would be a very huge security risk. Even more, when just initiated via an USB device. There are USB devices, which use certain behaviors of some OS's (like auto execution of specific types) to install a virus on the PC. But even then you cannot "just read" the data. It would be way more elaborate and not possible with a simple Arduino, thus off topic here. (And you might frown upon hacking your own PC this way)

From our point of view (means leaving the hacking off limits), I would aggree with Majenko in the comments. Using the visual output is the most viable and easy solution, though your results might vary.
For that you would need a camera pointing at the screen (check if you get a good image. It might be distorted due to slow refreshing...) and use a Raspberry Pi or similar to connect it. On the Pi you can then take pictures of the screen and use an OCR tool, which will read the text from the image. Then you need to extract and structure the relevant information. (Maybe it will be easier to create subimages in your program and let the OCR tool run over these to distiguish between the different data parts). Results will hardly depend on the quality of the image. If you can live with an additional program running the PC, you could instead make the images of the screen as screenshots, which will be way better quality. Though at that point you can also put the rest of the logic on the PC and just remove the Pi.
This way will still be hard to do for a beginner, but possible.

Thanks for the response

OCR seems really cumbersome, it is way easier to just write a pc program that connects over the network to your arduino or even send the files over your custom serial protocol.

@Ananashoi Though that still doesn't include how to get the data from the program. Often such programs don't have a "stream all data to this location" option. Sometimes they can export a fixed data set, though that export again needs to be triggered. That part really depends on the program and we don't know anything about it currently.


text:
Sketch is not being received by Arduino even though Arduino Editor acts like it is finished?
In my attached screen capture the Arduino Editor appears to be performing the upload, however it never finishes. Completes three steps, the last being the sketch up-load and then states that it is busy.  Sorry that I can't submit a short video. Please suggest ideas to solve this issue.  Maybe this is related to my first question?

there is no attempt to upload. it looks like Verify command, not Upload

Thank you to all who have suggested corrective action for my posted communication problem. After trying all of the suggestions, I threw up my hands and deleted all evidence of Arduino Create Editor. Next I installed the Arduino Create Editor as a fresh/new install. Magically, all of my communication issues with the Arduino Uno have been corrected. Apparently, something in the communication code was corrupted during my first attempt install on my desktop PC.

I would suggest you start with a simple blink example sketch and be sure it works. I believe it will. Your picture is almost impossible to read but i caught you have multiple libraries and several other problems. Look at the errors and resolve them one at a time. Until you do it will never load, that is the way it was designed. Be SURE there is only one file with the .ino extension unless it is also part of your sketch.

the screenshot shows successful compilation. so what about is this 'answer'?

I would suggest downloading the Arduino IDE and try that, it works great on linux mint. As far as the Amazon thing you might contact them for help. From what I can see it does not do the upload. The reason for the suggestion is to eliminate as many unknowns as possible.

the Amazon thing is the official Arduino Web IDE by Arduino. it is hosted on Amazon cloud


text:
Angle sensor to measure the stepper motor shaft rate of rotation
what Kind of Sensor that i can use to know how much angle stepper Motor shaft has rotated ?
Actually,I am thinking to rotate my stepper Motor at 1 rpm and my stepper Motor shaft Diameter is 8mm and length would be around 20 mm. I am using this stepper Motor in very sensitive Case that is the reason why iam  going to use microstepping Driver also.
Can anyone help me out form this query?
And ,Thanks in Advance.

What did your web recherche reveal? I would expect at least a few manufacturers providing such sensors. Over 20 years ago I was working on such a sensor that produces absolute angles, but had to abandon it before it was finished. It had a resolution of 1/1000 of a degree, giving 360'000 parts per revolution.

If skipping steps isn't a concern, you can just count the step pulses you sent to your driver.
If it is, you'd usually use an optical encoder.

You can get absolute position rotary encoders that are made for this task. Google them.

The datasheet on the stepper motor contains the number of steps per rotation. So divide 360⁰ by the number of steps to get the angle per step. Then it just a case of counting steps. The only issue is finding the 0⁰ position, so you'd need to add some mechanism to home the motor. Either manually, of with something like a limit switch.

Thank you for your Wonderful Response @Majenko ,I am going to run  at 1 rpm and I wanted to see the exact Speed while ist rotating and i wanted to know the exact angle is it possible with this ,and sorry for asking again:)


text:
unexpected output
I wrote some arduino code but since I don't have access to an arduino, ran it on a tinkercad circuit, the code is supposed to set all the buttons values to 1 and all the password values to 0 and the output "false password" as per the checkpassword function, but instead is outputting an infinite line of ÿÿÿÿÿÿÿÿÿÿÿÿ.
here is my code:
int i;
int passTrue[9];
int buttons[] {};

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

int * SetButtons() {
  for (int i = 1; i<=9; ++i) {
    buttons[i] = digitalRead(i);
 }
  return buttons;
}

int * SetPass() {
  i = 0;
  for (i = 1; i<=9; ++i) {
     if(buttons[i] == LOW) {
      passTrue[i] = buttons[i];
     }
  }
return passTrue;
}

  void CheckPass() {
    for(i=1; i<=9; ++i) {
      if(passTrue[i] != buttons[i]) {
        Serial.println("false Password");
      } else {
        Serial.println("correct password");
      }
    }
  }

void Test() {
  for(i=1; i<=9; ++i) {
   buttons[i] = 0;
   passTrue[i] = 1;
  }
}

  void loop() {
SetButtons();
SetPass();
Test();
CheckPass();

  }

it shouldn't be relevant but attached is also my circuit:

int buttons[] {}; - I've got a bad news for you - this is not doing what you think it does

And also passTrue has 9 elements and the first element is on index 0. But you are starting on second element and accessing one element after the array (Welcome to the Buffer overflow world).

ÿÿÿÿÿÿÿÿÿÿÿÿ usually indicates a baud rate mismatch.

Since TinkerCAD handles baud rate matching automatically that is not the problem.  But  your buttons array looks problematic. My hunch is that you are corrupting memory and it's causing weird printing behaviour.

Just take int buttons [9]; instead of int buttons [] {}; and it should work.


text:
Hc-05 bluetooth module pairing issue
Module light is blinking/working but it's not showing for pairing in my smart phone.I have supplied it 3.3 volts and have tried different phones.

what is your question? ... I do not see anything related to the Arduino in your post

I put together a complete tutorial on using the HC-05 in the Arduino environment for remote programming.  You can see it here

Your tutorial doesn't explain how to troubleshoot pairing problems.

It won't pair directly you will need other apps for pairing the modules. Try using this app. It will solve your issue for sure

You can't use that app until you connect to the device through the android OS


text:
Bluetooth connection problem
I am using Arduino Uno and Blue tooth HC-06, I am trying to use this in order to switch a LED through mt phone but I cannot create communication  between the Bluetooth and the Arduino, I am using software version 1.8.13 and I manage to pair to the Bluetooth through my phone, this is my code:
    char data = 0;                //Variable for storing received data
    void setup()
    {
    Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
    pinMode(13, OUTPUT);        //Sets digital pin 13 as output pin
    }
    void loop()
    {
    if(Serial.available() > 0)  // Send data only when you receive data:
    {
    data = Serial.read();      //Read the incoming data and store it into variable data
    Serial.print(data);        //Print Value inside data in Serial monitor
    Serial.print("\n");        //New line
    if(data == '1')            //Checks whether value of data is equal to 1
    digitalWrite(8, HIGH);  //If value is 1 then LED turns ON
    else if(data == '0')       //Checks whether value of data is equal to 0
    digitalWrite(8, LOW);   //If value is 0 then LED turns OFF
    }

}

and this is the image of the wiring:

I don't have any problem with the computer the software or the Arduino different codes I can run very easily the only problem is with the Bluetooth device
Thanks a lot

With what app your you trying to send the serial data? Are you using Andriod? The HC-06 will only be connected, if the app starts and holds the connection. So you cannot just connect the HC-06 just in the Andriod bluetooth settings. That is only for pairing. The actual connection is initiated by the app. Thats what I already stumbed across myself.


text:
Can I use this camera switcher?
I am wondering can I use this bicks camera switcher with the arduino since it uses a PWM signal.
If i can do I just put it on one of the PWM outputs or do I need to wire I add something to make it work.
**You can find the user manual here under attachments.**https://store.bicks.us/multiview/20-bicks-s-multiview-duo-fpv-camera-switcher.html

what do you mean by use with arduino?

can I use one of the pwm outputs to control it.(https://oscarliang.com/bicks-multiview-duo-camera-switcher/) for further reading

No one will read the user manual for you. This is not how StackExchange work, you read the manual and write the code, if there is any problem or question, come back here and ask the question.

Ok Thank you for letting me know

why not use a digital pin?  the PWM is for control with a radio RC

good idea, Thanks

The pwm output of an RC receiver is the same signal used to control a servo. So if you used the servo library with Arduino to control the pwm of this device it should work fine.


text:
Can I use The mpu6050 with this?
I am making a project with 3 arduinos (2 slave, 1 master) and I want to know can I use the mpu6050 since it uses the I2c communication.

You're using I2C for the Arduino->Arduino communication?

yes i am using  it

Yes, but only from the master. You have one I2C bus with three slave devices on it - two arduinos and one mpu6050.

thank you for the help

You can but keep the I2C wires less then about 30cm. If they are going to be further apart consider something like RS485 or CAN. Are you sure you need three?

Yes i do I am making a car/ drone combo https://www.youtube.com/results?search_query=smart+ideas+consept+drone&pbjreload=102


text:
Arduino binary LED 10 bit display
I'm working on a simple ADC project, the goal is to adjust the on/off of the LEDs according to the binary reading (1-on,0-off). I've tried this with 8 bit, and it works as intended. But on 10 bit, two of the LEDs with representation of 2^8 and 2^9 won't turn on even though the reading on the serial monitor is 1023 (should be 1111111111 -all LEDs on). I wonder if there's anything wrong with my code or circuit?
(I'm totally new to arduino, sorry for the noobness)
-I'm using Arduino UNO R3, the details are shown in the image
void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);

  Serial.begin(9600);
}

void loop(){
  int sensorValue = analogRead(A0);
  Serial.print("Decimal=");
  Serial.print(sensorValue);
  Serial.print("\tBinary=");
  Serial.println(sensorValue,BIN);

  if(sensorValue>=0&&sensorValue<=1023){
    digitalWrite(4,(sensorValue&1));
    digitalWrite(5,(sensorValue&2));
    digitalWrite(6,(sensorValue&4));
    digitalWrite(7,(sensorValue&8));
    digitalWrite(8,(sensorValue&16));
    digitalWrite(9,(sensorValue&32));
    digitalWrite(10,(sensorValue&64));
    digitalWrite(11,(sensorValue&128));
    digitalWrite(12,(sensorValue&256));
    digitalWrite(13,(sensorValue&512));
  }
  delay(20);
}

write a debug sketch ... turn on all of the LEDs ... does that work?

According to the official documentation, the second parameter of
digitalWrite() should be either HIGH or LOW. Thus, in order to be
compliant with the published API, you are supposed to write:
digitalWrite(12, sensorValue&256 ? HIGH : LOW);

In practice, digitalWrite() interprets any non-zero value as HIGH.
However, its prototype is:
void digitalWrite(uint8_t pin, uint8_t val);

Both parameters have the type uint8_t, which means “8-bit unsigned
integer”. If you provide a value that doesn't fit in 8 bits, the
implicit cast to uint8_t will reduce it modulo 28. Thus,
both 256 and 512 become zero through the implicit cast.

Your trinary operator trick would fix the 8 bit truncation problem AND send the documented values to the function. Personally, I'd write a function that took bit index and a value and returned HIGH or LOW, and call that. D.R.Y.

I know OP is new, but fancy not writing to ports for ganged output.

Seems, digitalWrite does not take any int != 0 as HIGH
Rather consider supplying a boolean (one byte value)
   digitalWrite(12,(sensorValue&256)==256);
   digitalWrite(12,(sensorValue>>8)&1);

or similar


text:
FIFO overflow with DMP on MPU6050 and OLED
I am using the DMP example code to get yaw pitch roll values, mainly I am interested in pitch value for building a self balancing robot. I am trying to display the pitch values on an OLED screen but I am getting FIFO overflow error which is resulting in delayed sampling and sometimes erratic values.
I tried adding a mpu.resetFIFO() after updating the OLED, but its causing a very slow sampling of the sensor.
I am keen on changing the Arduino Uno for a Teensy board(prolly teensy LC). My main concerns are will changing the processor help? Teensy LC runs @48Mhz compared to Arduino Uno which runs @16Mhz.
Also I went through this link which I found as a probable solution but wasn't able to do it
https://www.i2cdevlib.com/forums/topic/27-fifo-overflow/#comment-99
would be great if someone could guide me as to how do I do this?

I wasnt able to change the bit as instructed, but after some more reading I was able to, I think the OLED updating is causing a delay, which in turn is causing FIFO overrflow(as it might be slow). For now I am not adding  an OLED.
I tested my code on the bot seems like when the bot freaks out after couple of seconds trying to balance itself the values from MPU are erratic and the program freezes, have tried adding decoupling caps on my motors but it doesnt solve the issue. Really confused as to what is happening

if you can, please post your code ... or post a minimal code that still exhibits the problem ... maybe it can be optimized ... my thinking is to
handle MPU-6050 comm fully at every iteration of loop() and handle OLED comm in chunks


text:
Is 1MB flash enough for OTA upload in ESP-01?
I'am asking this question, because in my ESP-01 OTA upload always fail. In fact update won't even start. When update was triggered esp wifi led(build in blue) indicates "working" , but after cca one second esp reset itself. And The original program remains and starts again...

what Flash size did you select in Tools menu?

1MB(FS:none, OTA:~502KB).... according as I read in tutorial, that OTA has to be at least half of memory for propper running...

try to turn off firewall on PC

I tried, but with no effect...

Yes, 1MB is fine for OTA. There are, though, a few caveats when working with OTA that you must observe regardless of the flash size:

The maximum OTA program size is less than half the available flash size. Typically it is about 500kB. Two copies need to be stored in flash, plus the partition table and NVRAM. The rest of the flash on larger chips is most often dedicated to FS storage.
The device must first be programmed through USB with an OTA-compatible partition layout.
After programming through USB it must be manually reset or power cycled to set the boot mode correctly.
You can not change the partition layout over OTA programming. You need to make sure you have the same partition layout selected as when you originally programmed through USB.
ArduinoOTA.handle(); has to be called very regularly to handle the programming request. You can't have any blocking code in your sketch that might stop that from being called.

Observe all those and you should be able to program over WiFi with no problems.

I programmed it via USB, program works, OTA was shown in Tools>port options. Program still running... LED blinking... But when I press Upload code to device via OTA port ESP freeze and after few second IDE report error: No Answer, but very strange thing is that original program crashes and esp is unprogrammed... Than i have to upload code again with USB

And have you taken point 5 into account?

every point of your advice is fulfilled... My code is about 210 KB

In my void loop is only ArduinoOTA.handle(); no more rows...

@Sahasrar, point 3.?

For OTA uploads, the size of the compiled (old sketch + new sketch) should not exceed the flash size.
Due to this, large sketches (more than 500KB with 1MB flash) cannot be OTA uploaded directly if the sketch size exceeds half of the flash size.
However, this restriction can be circumvented by first uploading a sketch only with OTA features as given below:

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

char ssid[] = "xxxxxxxx"; //WiFI user id
char pass[] = "yyyyyy";   //WiFi password

#define OTA_Host_Name "ESP01S-EMPTY-OTA"

void setup()  {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);

  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    delay(5000);
    ESP.restart();
  }
  ArduinoOTA.setHostname(OTA_Host_Name);
  ArduinoOTA.begin();
}

void loop() {
  ArduinoOTA.handle();
}

This script will compile to around 300KB. Once this script is uploaded in flash, a script with upto 700KB can be uploaded through OTA to a 1MB flash!
Upload this script first. Then restart the controller and choose "ESP01S-EMPTY-OTA" as the port and upload the new updated script that you wish to upload!
IMPORTANT: Firewall must be turned OFF during OTA uploads.

are you sure? the partitions are selected in Tools menu. can it be changed with OTA?


text:
How to program Esp8266 remotly via wifi?
I hope it's not a sci-fi for arduino. But I saw that dual system with two MCU can program each other via radio connection. It has been done in experimental space cube projects.
It is theoretically possible? I'm thinking about two arduino MCU first of them will be main MCU and second will be like programming device via serial link.I want to program mcu via wifi without cable connection. Somehow send hex file via wifi to eeprom and upload to second device flash memory.
How do you see this issue? Is that a big nonsense?

Sure, no reason why this cannot be done. Every ESP8266 with enough flash memory has the ability to reflash itself over a wireless link (OTA), downloading a binary file containing its new flash contents from a web server. You can easily run such a web server on another ESP8266. You just have to code it.

The firmware update over WiFi is called OTA update. OTA stands for "over the air".
The esp8266 can OTA update itself. The Arduino library for this is called ArduinoOTA and it is bundled with the ESP8266 Arduino boards support package.
See the example for ArduinoOTA library in IDE Examples menu.
Other MCU have the self update option too. ESP32 has it of course, then for SAMD boards Arduino made WiFi101OTA library. For ATmega I made the ArduinoOTA library based on the WiFi101OTA library so it supports SAMD too. And it doesn't have to be WiFi. Cable works too.
The OTA update stores the uploaded firmware in free part of the flash and after successful upload it moves the firmware to target location and resets the MCU.
For any Arduino with SD bootloader OTA update is possible, because the library only has to store the uploaded firmware to the SD card and reset the MCU.
For small ATmega ftp bootloaders exists. Here the bootloader waits for network upload.
Update over a second MCU solutions are for MCU with less flash, mostly for the ATmega328p. The ESPLink firmware and the WiFiLink firmware for ESP8266 can flash attached ATmega328p over RX/TX. The ESP8266AVRISP can flash ATmega wired over SPI.
ArduinoIDE supports OTA upload. It creates a network port based on MDNS record propagated by the ArduinoOTA library or firmware with OTA support.

Other update way is to download the new firmware from a server or upload it over a web page. ESP8266 has for this ESP8266httpUpdate and ESP8266HTTPUpdateServer libraries. For SAMD, ATmega and other boards my ArduinoOTA library has examples on how to store and apply the update received as download or upload.

Thank you, I'll try it when I came home

I got it, It's pretty cool... Thanks :)


text:
Storing value in EEPROM in Arduino Uno
Hi I am a beginner in Arduino Uno. I wanted to store a value of 77880 in EEPROM and fetch it later. I made the code as follows to check my logic(I am using Arduino Uno) :
#include <EEPROM.h>
int addr = 0;
byte value;
void setup() {
  // put your setup code here, to run once:
  int val = 77880;
  EEPROM.write(addr, val);
  Serial.begin(57600);
}

void loop() {
  // put your main code here, to run repeatedly:
  value = EEPROM.read(addr);

  Serial.print(addr);
  Serial.print("\t");
  Serial.print(value);
  Serial.println();
  delay(1000);
}

but I am not getting the value of 77880 when I read the EEPROM address. instead I am getting a value of  56 in my serial output. Can anybody pls explain how should I implement the same?

EEPROM can only store the values 0-255 in any one address. That's the maximum range of an 8-bit value, and EEPROM "cells" are 8-bit in size.
You will have to split your value up into multiple 8-bit chunks and store each chunk at a different address - for example for 32-bit values you can use:
uint32_t val = 77880; // In hex is 0x13038
int addr = 0;
EEPROM.write(addr, val & 0xFF); // Stores 0x38 in address 0
EEPROM.write(addr + 1, (val >> 8) & 0xFF); // Stores 0x30 in address 1
EEPROM.write(addr + 2, (val >> 16) & 0xFF); // Stores 0x01 in address 2
EEPROM.write(addr + 3, (val >> 24) & 0xFF); // Stores 0x00 in address 3

Then to read you do the opposite and shift the values and OR them:
uint32_t val = (uint32_t)EEPROM.read(addr) |
               ((uint32_t)EEPROM.read(addr + 1) << 8) |
               ((uint32_t)EEPROM.read(addr + 2) << 16) |
               ((uint32_t)EEPROM.read(addr + 3) << 24);

Alternatively the EEPROM library has a "store anything" helper to do it for you:
EEPROM.put(addr, val);

That will store the variable val across enough cells to fit it (4 in the case of a 32-bit variable), so you must know not to write to the other cells used by it (0, 1, 2 and 3 in this case) or you will corrupt your data.
You recall it with:
EEPROM.get(addr, val);

Thank you for your prompt reply

See Majenko's answer for why you have to problem. This is alternative solution to the problem.
Using the Arduino library for EEPROM is very limited. It can only read/write one byte at a time. Your variable val is of the type int which is a 16 bit integer on the uno. So two bytes, which is also called a word.
I use the AVR EEPROM "library" directly.
#include <avr/eeprom.h>

EEMEM int eepVariable; // using EEMEM will make the compiler handle the location in EEPROM for you
                           // the compiler makes sure no data will ever overlap inside the EEPROM.

int value; //should be an `int` too.
void setup() {
  // put your setup code here, to run once:
  int val = 77880;
  eeprom_write_word(&eepVariable, val);
  Serial.begin(57600);
}

void loop() {
  // put your main code here, to run repeatedly:
  value = eeprom_read_word(&eepVariable);

  Serial.print(value);
  Serial.println();
  delay(1000);
}

"Using the Arduino library for EEPROM is very limited." You may not be aware, but this hasn't been true for years. See EEPROM.put(). You can write any type. The Arduino EEPROM library also lets you access the EEPROM as though it was an array, using the overloaded operator[], which is very convenient at times. The Arduino EEPROM library also will not unnecessarily cause wear. It only updates values. It won't rewrite bytes if they are already what you are writing. The Arduino EEPROM library is for sure what I recommend using, for these reasons.


text:
2 stepper cnc inaccurate
I'm building a simple cnc machine that just writes letters. It uses 2 steppers for x and y axis.
Here is how it works

generate letters in c# and convert them to list of lines
send to arduino mov_xy line.x line.y as string for each line
on arduino convert to int, multiply by steps per mm and run with speedy stepper

It eventually builds up to accuracy problems.
If it's writing "ZWX", letter "X" would be slightly to the side.
Things i tried:

500000 baud rate
accumulate remainder of float number of steps
different usb cables
different cnc machines

It is serial communication error?
Do i need to implement CRC?
Can UNO handle this?
Does SERIAL_8E1 do parity check automatically or do i need do something?
I went trough everything many times.
What am i missing here?

This image is generated directly from letter lines in c#, so i doubt the problem is on c# side.

reduce the complexity of the problem ... instead of ZWX, try engraving three simple squares

Instead of actually driving the motors, you could calculate the position. That would rule out inaccuracy from the motors. Send shapes, that return to the starting point. Add up all steps (the actual steps, after the conversion from the float number), as your CNC code would do with the motors. Then display the endposition, that comes out of your calculations. That would show the accuracy of the calculation part and you can see, if thats the problem.

I forgot to take care of negative steps in remainder accumulation.
This solved it.
// x accum
float resX = mmX * (float)X_STEPS_PER_MM;
float lresX = (long)resX;
_x_acum += resX - lresX;

long extraStepsX = 0;
while(_x_acum > 1.0f){
     _x_acum -= 1.0f;
     ++extraStepsX;
}

while(_x_acum < -1.0f){
     _x_acum += 1.0f;
    --extraStepsX;
}
// move stepper for lresX + extraSteps


text:
2 stepper drivers speed control
I'm using two tb6600 to control two step motors. It's for letter writing cnc machine.
Moving single axis works fine.
I want to push 2 steppers in the same time along a diagonal.
I tried to calculate ratio x:y, so if x is making more steps than y for 1 y do n x steps. This worked, but machine was shaking no mater how i adjusted delays between step high and low. When i use PWM there is no shaking, but i can't figure out how to make it follow diagonal.
Second try was to use PWM with analogWrite.
if(delayX > delayY){
      analogWrite(stepPinX, 128);
      analogWrite(stepPinY, 128);

      delay(delayY);
      analogWrite(stepPinY, 0);
      delay(delayX - delayY);
      analogWrite(stepPinX, 0);

    }else if(delayX <= delayY){
      analogWrite(stepPinX, 128);
      analogWrite(stepPinY, 128);

      delay(delayX);
      analogWrite(stepPinX, 0);
      delay(delayY - delayX);
      analogWrite(stepPinY, 0);
    }

This doesn't works obviously. It reaches end point, but it doesn't follow diagonal.
If i set duty cycle to 2 or 128 it doesn't matter.
Isn't duty cycle supposed to change speed of stepper motor?
What am i missing here and how can this be done?

No, PWM won't change the speed - you're pulsing the STEP input of your stepper drivers, where each signal edge will create a movement. PWM only changes the duration of the HIGH and LOW sections of that movement, not the frequency (which would change the speed).
You'll probably want to use a library designed to handle stepper motors / drivers.

Changing the duty cycle does not change the frequency of the PWM signal.
The tb6000 needs a pulse to trigger a step of the motor. If the frequency does not change the pulses per second do not change too and thus the speed is constant.
If you control just one motor the method of using delays to control the frequency works.
But in the case of two motors with different speed you need counter variables to immetate two frequencies (speeds) you need to control each speed of the motors.
First you caculate the ration of the speeds (you said y=1 and x=n steps. Then, the ratio is n:1, i.e the X Motor is faster then the Y Motor by factor n).
The following is just an incomplete example to explain my idea.
int cntX = 0;
int cntY = 0;

// I don't know you value n
// Let's say n=5
int ratioX = 5;
int ratioY = 1;

// One step per second at max speeed
// choose whatever fits your needs
int delayForMaxSpeed = 1000;

const int stepPinX = 5;
const int dirPinX = 2;
const int stepPinY = 6;
const int dirPinY = 3;
const int enPin = 8;

void setup()
{

  pinMode(stepPinX,OUTPUT);
  pinMode(dirPinX,OUTPUT);
  pinMode( stepPinY, OUTPUT );
  pinMode( dirPinY, OUTPUT );

  pinMode( enPin, OUTPUT );
  digitalWrite( enPin, LOW );

}

void loop()
{
  // Enables the motor to move in a particular direction
  digitalWrite( dirPin, HIGH );

  countx++;
  county++;

  if ( countX >= ratioX )
  {
     countX = 0;
     digitalWrite( stepPinX, HIGH );
  }

  if ( countY >= ratioY )
  {
    countY = 0;
    digitalWrite( stepPinY, HIGH );
  }

  delayMicroseconds( 500 );

  digitalWrite( stepPinX, LOW );
  digitalWrite( stepPinY, LOW );

  delay( delayForMaxSpeed );
}


text:
Is it possible to write data to a fat file system on SPI flash using an arduino?
I have an SPI flash based mp3 module and was wondering whether its possible to write to the flash chip using a microcontroller(arduino). the IC supports FAT16/FAT32 file systems. I have researched arduino and the fat file system but they are all in relation to SD cards which operate differently as far as i understand. Is it possible to write data to a fat file system on SPI flash using an arduino?

Isn't that SPI flash on this board already connected to the boards controller? I think SPI not multi-master capable. So you would need to disconnect the flash from the boards controller

yes it is. but i wanted to load new content onto it using a MCU.

But that means, that the first important question is, how to communicate with the flash chip, without conflicting with the boards MCU. At that point the filesystem is irrelevant.

I'd thought that since its possible to write files onto the chip from a computer it might be possible to do the same thing with an external MCU

Most likely the USB port connects to the boards MCU, which then in turn connects via SPI to the flash chip. So for the flash chip it is equal if you write data via USB or play music on the board. Both are only SPI communications with the boards MCU. My guess is, that you either need to extract the flash chip from the board and add some kind of multiplexer to it (so that you can switch between the SPI connections to the internal MCU and your external one), or that you need to use an USB host board with your external MCU to write data through the USB interface.

hmmm yes that makes sense. usb host boards is an interesting thought, new concept to me, i will look into that.(and update if there is any success) thanks very much for the help.

The first and most important problem is not the filesystem. Currently on the board the USB port is connected to the internal MCU, which in turn is connected via SPI to the flash chip. The internal MCU is the master on the SPI bus. But the SPI bus does not support multiple masters on one bus. So just connecting the external MCU to the SPI lines as master would not work.
I see 2 possible ways to go here:

You can unsolder the flash chip from the board and add a fitting multiplexer chip, which can switch the SPI lines between the two masters. That effectively gives you only one master on the SPI bus at any time. This way would be rather hacky and difficult for a beginner. It might also be important to keep an eye on the capacitance of the bus, since it might run with rather high speed. A too high capacitance (for example through using a breadboard) might result in erroneous communication.
Then you could use one of the FAT libraries. I don't know them in detail, but I think you could also use them for a simple SPI flash chip. You just would need to implement the lower level access functions, that the FAT library needs.

Or you could try to use a USB host board with your external MCU and try to write data through the USB port. I don't have much experience with USB host boards, so I cannot really tell you, if and how exactly this is possible with the available hardware (the board will most likely implement an USB interface like a simple flash USB stick).

All in all I think, this would be rather hacky. Your board is not really made for changing the data through another microcontroller. Depending on what exactly you want to achieve, you might want to go to a different hardware setup.

Thanks very much for taking the time to answer. much appreciated.


text:
Serial doesent work when calling function from timer
You can try the code on your arduino UNO to better understand what is hapening in serial monitor!
I want to calculate jacobian matrix from rotation matrix!
float jakMATB[3][3] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
     };
float POKUS = 0;
float k = 0.000001;
float dt = 0.001;
float b = 90 * (PI / 180);
float vnB[3] = {0, 1, 0}, vpB[3] = {0, 1, 1};
float nB[3] = {0, 1, 0};
float nBplus[3] = {0 , 1, 0};
float nBminus[3] = {0, 1, 0};
void setup() {
Serial.begin(9600);
Serial.print("init ok");
cli();//stop interrupts
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1  = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = (16000000) / ((1 / dt) * 1024) - 1; // 15624 = (16*10^6) / ((1)*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupts
}

when I call the function in loop everithing works fine and I get  1 2 1 in serial monitor
 void loop() {
 izracunJAKOB();
 for (int j = 0; j <= 2; j++) {
for (int i = 0; i <= 2; i++) {
  Serial.print(jakMATB[j][i]);
  Serial.print(" ");
}
Serial.println("");
}
}

when I call izracunJAKOB() with timer interupt Serial monitor
stops working and doesent event write "init ok"
ISR(TIMER1_COMPA_vect) {
  //izracunJAKOB();
 }
void izracunJAKOB() {
for (int j = 0; j <= 2; j++) {
for (int i = 0; i <= 2; i++) {
  nBplus[j] = nB[j] + k;
  nBminus[j] = nB[j] - k;
  float matricaBplus[3][3] = {
    {cos(b) + nBplus[0]*nBplus[0]*(1 - cos(b)), nBplus[1]*nBplus[0]*(1 - cos(b)) - nBplus[2]*sin(b), nBplus[0]*nBplus[2]*(1 - cos(b)) + nBplus[1]*sin(b)},
    {nBplus[1]*nBplus[0]*(1 - cos(b)) + nBplus[2]*sin(b), cos(b) + nBplus[1]*nBplus[1]*(1 - cos(b)), nBplus[1]*nBplus[2]*(1 - cos(b)) - nBplus[0]*sin(b)},
    {nBplus[0]*nBplus[2]*(1 - cos(b)) - nBplus[1]*sin(b), nBplus[1]*nBplus[2]*(1 - cos(b)) + nBplus[0]*sin(b), nBplus[2]*nBplus[2]*(1 - cos(b)) + cos(b)}
  };
  float matricaBminus[3][3] = {
    {cos(b) + nBminus[0]*nBminus[0]*(1 - cos(b)), nBminus[1]*nBminus[0]*(1 - cos(b)) - nBminus[2]*sin(b), nBminus[0]*nBminus[2]*(1 - cos(b)) + nBminus[1]*sin(b)},
    {nBminus[1]*nBminus[0]*(1 - cos(b)) + nBminus[2]*sin(b), cos(b) + nBminus[1]*nBminus[1]*(1 - cos(b)), nBminus[1]*nBminus[2]*(1 - cos(b)) - nBminus[0]*sin(b)},
    {nBminus[0]*nBminus[2]*(1 - cos(b)) - nBminus[1]*sin(b), nBminus[1]*nBminus[2]*(1 - cos(b)) + nBminus[0]*sin(b), nBminus[2]*nBminus[2]*(1 - cos(b)) + cos(b)}
  };
  jakMATB[i][j] = (matricaBplus[i][j] - matricaBminus[i][j]) / (2 * k);
  nBplus[0] = 0;
  nBplus[1] = 1;
  nBplus[2] = 0;
  nBminus[0] = 0;
  nBminus[1] = 1;
  nBminus[2] = 0;
}
}
}

//////////////////////////////
when I comennt out
   nBplus[j] = nB[j] + k;
   nBminus[j] = nB[j] - k;

and
   nBplus[0] = 0;
   nBplus[1] = 1;
   nBplus[2] = 0;
   nBminus[0] = 0;
   nBminus[1] = 1;
   nBminus[2] = 0;

Serial works just fine
when I coment out only  matricaBminus and  matricaBplus serial works fine
Please help! It surely is a stupid solution!

I only get hello world in Serial. Did I get overflow on MCU?

Though that might not be the cause of your problem, do you put the printing of the matrix in loop() into a critical section (with interrupts turned off)? If not, the interrupt might happen in the middle of printing. Please show a complete example sketch for the interrupt version of the code.

@chrisl Timer was to fast! When I decreased frequency everithing worked fine.

It generally not advised to use serial inside an interrupt.

It is even impossible to use Serial in an interrupt, if you risk to overflow the output buffer. You cannot write more than 63 characters (to normal arduinos) from an ISR.

Timer was to fast! When I decreased frequency everithing worked fine.

Increasing the baudrate to something higher that 9600 also helps.

This may seems to solve your problem, however, it is not a best practise for the way you using interrupt. You should read interrupt by Nick Gammon.


text:
Servos jitter when powered by power module
I need 48 sg90 servos to move to a specific position each minute. Now I am using two arduino mega boards to power everything through 6 bread boards but it seems I need more power because some servos are ticking and are delayed. I cant get the external power supply to work independently of the computer. Once I unplug from my computer the servos jitter. Any help would be greatly appreciated.

...Schematic...?

make sure you have connected all the grounds together, i mean from both the Arduino boards, i had similar issue when using ESP8266 module and Arduino UNO together! check this first and also make sure the power supply is regulated and sufficient for your needs.

Most servos use an analog signal (width of a pulse) for positioning.  Any perturbation in that signal will cause unexpected behavior.  Activating 48 servos simultaneously will likely indirectly or directly affect the analog signal.

The unexpected behavior might be mitigated through changes in software or hardware.  These mitigation efforts may include:

Staggering the servo changes so that only 1 servo moves at a time.
Perhaps less effective but worth trying, staggering the servo changes so only 1 servo starts moving at a time.  In this scenario more than 1 servos may be moving at a time.
Using a power supply which maintains the expected voltage even during events such as all servos starting simultaneously.

These are only 3 options to consider.  Many more exist but may not be pertinent to your situation.  More information is needed.

For 3: A short power surge could also be handled with a big capacitor between Vcc and ground. Those could provide the current needed for the spike and prevent the voltage from dropping


text:
Trying to use Nano Every as a sort of USB logic analyzer, but can't isolate it from "device under observation"
Here's the scenario: I have a radio that displays information on a 1602A LCD. The 1602A is plugged into a header so I can easily pull it out and instead plug in logic analyzer leads. The logic analyzer decodes the HD44780 protocol and shows me the data that would have gone to the 1602A. The logic analyzer, not surprisingly, doesn't have any noticeable effect on the radio.
Now I want to replace the logic analyzer with a Nano Every. I wired it up so that the signals to be observed are connected to digital input pins on the Every. The Every is powered through USB and doesn't intentionally draw any power from the radio. Everything runs as expected and the Every shuffles readings to the PC via serial. HOWEVER, in this combination, the radio draws at least twice as much current from the power supply and the radio's voltage regulators begin to heat up substantially!
I would have thought that the digital input pins of the Every are high enough impedance that it would have no significant effect on the radio, just like the logic analyzer didn't. I can only assume that "significant" current is flowing from the radio's LCD header into the Nano Self's input pins, since they are the only connection between the radio and the Nano.
So, I guess my question is this: How can I make the Nano Self work more like a logic analyzer? Do I need additional circuitry between the signals being tested and the Self's input pins, perhaps logic buffers? Or might something else be going on here?

you may have one of the pins set as an output ... determine which pin(s) are causing the problem ... please post your code if you can

This is my first time working with the port registers and I had "PORTD.DIRCLR = 11111111; // Set the entire port to INPUT". I think it should have been B00000000 instead, correct?

11111111 is a decimal number ... B11111111 is binary .... you could do DDRD = B00000000; to set the D register pins as inputs

Sorry, that was a typo -- the code had the B prefix for the binary literal. I don't think DDRD is even defined for the Arduino Nano Every or other ATMega4809 based Arduinos. It might be if "registrly emulation" is selected under Tools in the IDE, but I decided to use the new port registers instead..

@jsotola was correct and the software defined pin directions incorrectly. Looks like I fried one of the pins in the process (multimeter shows continuity between the pin and ground), but when I rewired to a new pin on Port D and ran the corrected software, everything seems to work as expected!


text:
Invalid data using GPS TinyShield module with Tinyduino
I am new in GPS modules and I need to get the NMEA data from my GPS module but when I execute my code all the NMEA sentences are Invalid.
I am using the same example from instructables Tiny GPS Tracker https://www.instructables.com/Tiny-GPS-Tracker/ and it does not work. So I found other code examples and changed them a little bit.
My code is below. I have the GPS_RX wired with Arduino TX and the same logic for GPS_TX-Arduino RX and Baud is 9600, all these details are inside GPS.h.
If I change the wiring between TX and RX or gps baud the system does not work at all, so I strongly believe that these values are correct.
#include "GPS.h"
#include <SD.h>

#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#include <SoftwareSerial.h>
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#include "SoftwareSerialZero.h"
#endif

const int chipSelect = 10;
int cardPresent;

// The GPS connection is attached with a software serial port
SoftwareSerial softSerial(GPS_RXPin, GPS_TXPin);

#define Gps_serial softSerial

void setup()
{
  Gps_serial.begin(GPSBaud);
  SerialMonitorInterface.begin(115200);
  while (!SerialMonitorInterface && millis() < 5000); //On TinyScreen+, this will wait until the Serial Monitor is opened or until 5 seconds has passed

  gpsInitPins();
  delay(100);
  SerialMonitorInterface.print("Attempting to wake GPS module.. ");
  gpsOn();
  SerialMonitorInterface.println("done.");
  delay(200);

  //Enable and set interval or disable, per NMEA sentence type
  Gps_serial.print(gpsConfig(NMEA_GGA_SENTENCE, 0));
  Gps_serial.print(gpsConfig(NMEA_GLL_SENTENCE, 0));
  Gps_serial.print(gpsConfig(NMEA_GSA_SENTENCE, 0));
  Gps_serial.print(gpsConfig(NMEA_GSV_SENTENCE, 0));
  Gps_serial.print(gpsConfig(NMEA_RMC_SENTENCE, 1));
  Gps_serial.print(gpsConfig(NMEA_VTG_SENTENCE, 0));
  Gps_serial.print(gpsConfig(NMEA_GNS_SENTENCE, 0));

  SerialMonitorInterface.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (SD.begin(chipSelect)) {
    SerialMonitorInterface.println("card initialized.");
    cardPresent = true;
  } else {
    SerialMonitorInterface.println("Card failed, or not present- continuing with serial output");
    cardPresent = false;
  }
}

void loop() {
  handleGPS();
}

char waitForCharacter() {
  while (!Gps_serial.available());
  return Gps_serial.read();
}

void handleGPS() {
  while (Gps_serial.read() != '$') {
    if(!Gps_serial.available()){
      return;
    }
  }
  int counter = 1;
  char c = 0;
  char buffer[100];
  buffer[0] = '$';
  c = waitForCharacter();
  while (c != '*') {
    buffer[counter++] = c;
    if(c=='$'){//new start
      counter=1;
    }
    c = waitForCharacter();
  }
  buffer[counter++] = c;
  buffer[counter++] = waitForCharacter();
  buffer[counter++] = waitForCharacter();
  buffer[counter++] = '\r';
  buffer[counter++] = '\n';
  buffer[counter] = '\0';

  buffer[1] = 'G';
  buffer[2] = 'P';

  gpsDoChecksum(buffer);

  if (cardPresent) {
    File dataFile = SD.open("gps.txt", FILE_WRITE);
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.write(buffer, counter);
      dataFile.close();
    } else {
      SerialMonitorInterface.println("error opening gps.txt");
      cardPresent = false;
    }
  } else {
    SerialMonitorInterface.print((char *)buffer);
  }
}

After I wait aprox. 30 seconds which is the cold start of the gps I still receive invalid NMEA sentences.
(I tested it outdoors and indoors)
$GPRMC,181341.901,V,,,,,,,211020,,,N4B
$GPRMC,181342.901,V,,,,,,,211020,,,N48
$GPRMC,181343.901,V,,,,,,,211020,,,N49
$GPRMC,181344.901,V,,,,,,,211020,,,N4E
$GPRMC,181345.901,V,,,,,,,211020,,,N*4F
Can someone explain to me what is going on?

V stands for invalid sentence, I can't find a way to generate valid sentences

looks like the module is not able to determine location .... maybe not enough satellites are being received .... perhaps the GPS module has a setting for sensitivity level ... maybe the antenna is bad, or badly connected ... this does not appear to be an Arduino problem .... just a note: your code is overly complicated for debugging ... all that is required, is to copy the received characters to SerialMonitor .... see the SoftwareSerial example in the Arduino IDE

I tried similar code that only prints the sentences and the validity, but all of them were invalid. I tried the same code outdoors but same results.   Could it be faulty antenna??

think about it logically ... the module is generating valid sentences ... that means that the serial communication is good ... the module itself is saying that the data in the sentences is invalid, probably because the lat/lon info is missing ... so the problem is either configuration, or the module hardware on the satellite receiver side

Do you know if there is a way to print the number of satellites connected to the GPS module?

Using example sketches give invalid results also haha

looks like you may want either GGA, or GSA sentence .... https://web.archive.org/web/20200131031033/www.gpsinformation.org/dale/nmea.htm

So you say that i need to check those sentences in order to understand if the gps is fixed or not..

all I am saying is, look at the type of information that can be obtained from these various sentences  .... it is up to you to to decide if the information is useful to you .... personally, i would print out as many different sentences as possible and look at them  .... i would also try to find out if there is a command available that dumps multiple different sentences at once ..... here is a similar web page that is still alive http://aprs.gids.nl/nmea/  ..... note: GSV lists satellites in view


text:
Connecting two sensors to one analog pin
I am completely new to programming with Arduino so please bear with me if this seems stupid.
I am using an Arduino Uno R3.
I have two sensors, a Soil Moisture sensor and an LDR Light Sensor. Both of them have one pin marked as A0 on them. So now, do I connect them both to A0 using a breadboard (Like how I am connecting multiple sensors' VCC to the 5V pin currently) OR do I use a different analog pin say A0 for one and A1 for the other? Will it make a difference?

AO is not "Ay Zero", it's "Ay Oh", and stands for "Analog Output". It means it just sends a varying voltage. It really doesn't care where it's sent to, it just sends it.
It's up to you where you connect that output to. But suffice it to say it wants to be connected to an input that can read an analog signal. And the Arduino has 6 of them.
Which one you connect it to is entirely up to you - you just have to read from that analog input by using the right pin number in analogRead().

(https://i.sstatic.net/Rm3On.jpg)
you can simply connect one in the A0 and the other in the A1 since all those pins can be used for the same function


text:
Arduino Yun Disk Expander low memory but it looks like my memory is fine
I can't quite understand this when I run arduino yun disk expander sketch with a sd card plugged in I get the the following message. You do not have enough flash memory need 1mb. I ssh into my arduino and I get this
Filesystem                Size      Used Available Use% Mounted on
rootfs                    6.9M    632.0K      6.3M   9% /
/dev/root                 7.5M      7.5M         0 100% /rom
tmpfs                     29.8M    148.0K     29.7M   0% /tmp
tmpfs                     512.0K       0    512.0K   0% /dev
/dev/mtdblock3            6.9M    632.0K      6.3M   9% /overlay
overlayfs:/overlay        6.9M    632.0K      6.3M   9% /
/dev/sda1                29.7G      2.4M     29.7G   0% /mnt/sda1

The only thing that is full is the /dev/root but the reading I have done through the posts here and online say that's fine. Why may this be I am quite confused???

I don't have a YUN or a lot of experience with OpenWRT, so I'm not sure I'm going to be of much help but, I'm guessing the error you're seeing is from this line of the sketch.
Excerpting that here:
Process awk;

awk.runShellCommand(F("df / | awk '/overlay/ {print $4}'"));
int output = awk.parseInt();
if (output < 1000) {
  Serial.println(F("\nYou don't have enough disk space to install the utility software. You need to free at least 1MB of Flash memory.\nRetry!"));
  halt();
}

So, it appears they are executing df / | awk '/overlay/ {print $4}' on the YUN.
They're using awk to extract the fourth column ($4) of the line containing overlay (/overlay/), which by the way is awfully hackish.
Given that they expect the result of awk.parseInt() to compare less than 1000 to mean you have less than 1 Mbyte available, it's fairly clear they expected this column to be reported in kilobytes.  And yet in your own df listing
overlayfs:/overlay        6.9M    632.0K      6.3M   9% /

the fourth column is 6.3M and the rest are choosing different units, what is sometimes called "human" output.  So, we know what they care about is the overlay mount point.  And that at the time someone tested this code it either they didn't try an SDCard of any size or the output of df was different back then, which is why parsing something like df isn't a good idea.
And that's about as far as I can take you with any real confidence.  I don't know how overlay is set up on a YUN.
I guess, if you wanted to "fix" the code with a minimal change, it would be to add -k to the df command-line to force kilobyte based output, assuming -k works on whatever df comes with YUN.  If you wanted to go a step further, I suppose you could use -P to get POSIX output from df, again assuming that's supported, and change the expected units in the sketch accordingly.  But if this is just for you, and you know overlay has more than 1 MB free, you could just as easily change the function so it cannot fail:
void haltIfInternalFlashIsFull() {
}

All that said, I wouldn't be surprised if you run into another problem just like this in another part of the sketch.

yeah I got an error err. installing e2fsprogs dosfstools fdisk rsync kmod-fs-ext4 I've hacked away at this yun for a while. Such a headache. Dont know what to do at this point. Thanks anyways

Given that it will probably be a long drawn out process, I'd steer your toward something interactive like a chat network for forum.  About the only other thing I'll add here is that since most of the sketch seems to be executing shell command-lines on the YUN, you may get better help from people more knowledgeable in OpenWRT than in Arduino.

Ok I will look in those forums. Thanks Im gonna select your answer because it solved the initital problem I had. Thanks


text:
ATTINY85 - RF Transmitter (RH ASK)
I am working on a small RF sensor powered by a battery.
I used the code from Mr K. (https://arduino.stackexchange.com/a/55516/65870) as base and adapted it to the RH Ask protocol:
#define F_CPU 8000000  // This is used by delay.h library

#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <util/crc16.h>

#define LED_PIN           0

#define TX_PIN            4 //3
#define TX_BAUDRATE       2000
#define TX_MILLIINTERVAL  (1000UL/TX_BAUDRATE)
#define TX_MICROINTERVAL  (1000000UL/TX_BAUDRATE)
#define TX_MAXLEN         12
#define RFRepetitions 3
byte RollingCounter = 0;

// Define sensor IDs (for MQTT)
#define SensorIDMoisture 6

// Define moisture sensor variables
#define MoistureSensorPinA    A1
#define MoistureSensorPinD    10
#define MoisturePowerOutPin   1
#define RFPowerPin            3 //4

inline void led(const bool onOff) { digitalWrite(LED_PIN, onOff ? HIGH : LOW); }
inline void tx(const bool onOff) { digitalWrite(TX_PIN, onOff ? HIGH : LOW); }

const uint8_t header[8] = { 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x38, 0x2C };
const uint8_t conv4to6[16] = { 0x0D, 0x0E, 0x13, 0x15, 0x16, 0x19, 0x1A, 0x1C,
                               0x23, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x32, 0x34 };

// Watchdog timer
#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// Important: Sleep time equals the wdt_length setting multiplied by the wdt_loops_max
#define wdt_loops_max 225
#define wdt_length 9 // 9 = 8 seconds

volatile int wdt_loops = wdt_loops_max; // Start with maximum value in order to have a measurement when powering on the system

void rawSend(const uint8_t * p, uint8_t len) {
  while (len--) {
    const uint8_t val = *p++;
    for (uint8_t mask = 1; mask != 0x40; mask <<= 1) {
      tx(val & mask);
      delayMicroseconds(TX_MICROINTERVAL);

//      _delay_ms(TX_MILLIINTERVAL);
    }
  }
}

void send(const uint8_t * buf, const uint8_t len) {
  #define RH_ASK_HEADER_LEN 4
  //  First create the payload ...
  static uint8_t payload[(TX_MAXLEN+3+RH_ASK_HEADER_LEN)*2];
  uint8_t * p = payload;
  uint16_t crc = 0xFFFF;
  uint8_t v = len + 3 + RH_ASK_HEADER_LEN;
  crc = _crc_ccitt_update(crc, v);
  *p++ = conv4to6[v >> 4];
  *p++ = conv4to6[v & 0x0F];

  uint8_t _txHeaderTo = 0xff;
  uint8_t _txHeaderFrom = 0xff;
  uint8_t _txHeaderId = 0;
  uint8_t _txHeaderFlags = 0;

    // Encode the headers
    crc = _crc_ccitt_update(crc, _txHeaderTo);
    *p++ = conv4to6[_txHeaderTo >> 4];
    *p++ = conv4to6[_txHeaderTo & 0xf];
    crc = _crc_ccitt_update(crc, _txHeaderFrom);
    *p++ = conv4to6[_txHeaderFrom >> 4];
    *p++ = conv4to6[_txHeaderFrom & 0xf];
    crc = _crc_ccitt_update(crc, _txHeaderId);
    *p++ = conv4to6[_txHeaderId >> 4];
    *p++ = conv4to6[_txHeaderId & 0xf];
    crc = _crc_ccitt_update(crc, _txHeaderFlags);
    *p++ = conv4to6[_txHeaderFlags >> 4];
    *p++ = conv4to6[_txHeaderFlags & 0xf];

  for (uint8_t l = len; l--;) {
    v = *buf++;
    crc = _crc_ccitt_update(crc, v);
    *p++ = conv4to6[v >> 4];
    *p++ = conv4to6[v & 0x0F];
  }
  crc = ~crc;
  v = (uint8_t)crc;
  *p++ = conv4to6[v >> 4];
  *p++ = conv4to6[v & 0x0F];
  v = (uint8_t)(crc >> 8);
  *p++ = conv4to6[v >> 4];
  *p++ = conv4to6[v & 0x0F];

  //  Now transmit the header and the payload ...
  rawSend(header, sizeof(header));
  rawSend(payload, (len + 3 + RH_ASK_HEADER_LEN)*2);
  tx(false);

  //Serial.print("CRC: ");Serial.println(crc);
}

ISR(WDT_vect)
{
  wdt_loops++;
}

// Sleep
void system_sleep() {
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                        // System sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

// Setup for Watchdog
void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
//  pinMode(LEDPin, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  led(false);

  // Initialize moisture sensor
  pinMode(MoistureSensorPinD, INPUT);

  // RF sensor initialization
  //driver.init();

  setup_watchdog(wdt_length); // approximately 8 seconds sleep

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if(wdt_loops >= wdt_loops_max)
  {
    //digitalWrite(LEDPin, HIGH);
    led(true);

    wdt_loops = 0;
    moisture_measurement();

    led(false);
  }
  system_sleep();

}/* --(end main loop )-- */

void moisture_measurement()
{
  // Activate sensor
  analogWrite(MoisturePowerOutPin,255);
  analogWrite(RFPowerPin,255);
  _delay_ms(150);

  // Turn On RF transmitter

  float MoistureMedian   = 0;
 // float sensorValue;
  for(int i = 0;i<=100;i++)
  {
    float sensorValue = analogRead(MoistureSensorPinA);
//    moisture_percentage = ( 100 - ( (sensorValue/1023.00) * 100 ) );
//    moistureSensorSum += moisture_percentage;

    MoistureMedian += ( 1 - ( (sensorValue/1023.00) * 1 ) );
    //delay(1);
    _delay_ms(1);
  }

  // Read digital values
  bool digitalValue = digitalRead(MoistureSensorPinD);

  // Switch off sensor
  analogWrite(MoisturePowerOutPin,0);

  // Transmit value
  TransmitSensorValue(SensorIDMoisture,MoistureMedian);

  _delay_ms(150);
  // Turn Off RF transmitter
  analogWrite(RFPowerPin,0);

}

void MessageEncrypt(int adressIn, int parameterIn, float payloadIn, byte pByteArray[])
{
  pByteArray[0] = (byte)adressIn;

  byte * payloadBArray = (byte *)&payloadIn;
  pByteArray[1] = payloadBArray[0];
  pByteArray[2] = payloadBArray[1];
  pByteArray[3] = payloadBArray[2];
  pByteArray[4] = payloadBArray[3];

  RollingCounter = RollingCounter + 1;
  if(RollingCounter > 2)
    RollingCounter = 0;

  pByteArray[5] = RollingCounter;
}

//CRC-8 - based on the CRC8 formulas by Dallas/Maxim
//code released under the therms of the GNU GPL 3.0 license
byte CRC8(const byte *data, byte len) {
  byte crc = 0x00;
  while (len--) {
    byte extract = *data++;
    for (byte tempI = 8; tempI; tempI--) {
      byte sum = (crc ^ extract) & 0x01;
      crc >>= 1;
      if (sum) {
        crc ^= 0x8C;
      }
      extract >>= 1;
    }
  }

  return crc;
}

void TransmitSensorValue(int SensorID, float SensorValue)
{
  byte MessageOut[6];
  MessageEncrypt(SensorID, 1, SensorValue, MessageOut);

    for(int i=0;i<RFRepetitions;i++)
    {
      send((const uint8_t *)&MessageOut, sizeof(MessageOut));
    }
}

The code runs like a dream as long as I use 2000 as baudrate. As soon as I use another baudrate (500 or 1000) my test receiver does not receive any messages.
Any ideas what is going wrong here?
Thanks :)

I found the problem.
I used 2 2032 battery to power the attiny85. The internal clock of the chip is not precise enough when running at 6V. To solve the issue I removed 1 battery. The alternative would be to set the baudrate of the transmitter and receiver to different values (I had to set the receiver to 520 bdps to receive the messages from the transmitter with 500 bdps).
Maybe somebody can reuse my code for his project.


text:
Problem with using SD and Adafruit_SSD1306 libraries at the same time
I am searched over the internet and found out a few similar questions, but non of them were helpfull, so I decided to open a new quetion.
I tried both SD and Adafruit_SSD1306 libraries and they both worked fine when they were separated - in different codes. The error came when I used them in one code.
In my programme I try to init SD card, write to it and then init dispaly (everything works fine). After that I do another write cycle into the SD, but I get an error in opening a file:
error opening test.txt

In other words I cant write anything into the SD card after oled display is initialized (display works then without any problems).
Here is my code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <SPI.h>
#include <SD.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

TwoWire Wire1(PB9, PB8);// Use STM32 I2C2
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);

const int chipSelect = PA15;

void setup() {

    Serial1.begin(9600);
   if (!SD.begin(chipSelect)) {
    Serial1.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial1.println("card initialized.");

 for (int i = 0; i < 10; i++)
  {
  File dataFile = SD.open("test.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println("Test");
    dataFile.close();

    Serial1.println("Test");
  }
  else {
    Serial1.println("error opening test.txt");
  }
delay(30);
  }

  delay(2000);

 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial1.println(F("SSD1306 allocation failed"));
  }

  delay(500);

  for (int i = 0; i < 10; i++)
  {
  File dataFile = SD.open("dat_test.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println("Test");
    dataFile.close();

    Serial1.println("Test");
  }
  else {
    Serial1.println("error opening test.txt");  //here is the error I get
  }
delay(30);
  }
}

void loop() {
}

Here is the output:
card initialized.
Test
Test
Test
Test
Test
Test
Test
Test
Test
Test
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt
error opening test.txt

I am using STM32F103CB.

and how do you connect the SD card? what dev board do you use? a Blue Pill?

Have you tried commenting out the display call between the two file-write sequences, and will the second write-sequence run then?

@JRobert, yes I tried that and both SD writings worked fine. Its very wierd, because it only happend after the OLED init.

@Juraj SD card is connected via SPI (PB3 - SCK, PB4 - MISO, PB5 - MOSI, PA15 - CS), OLED display uses I2C (PB8 - SCL, PB9 - SDA) and I am using my own custom board.

the experts are here https://www.stm32duino.com


text:
Problem with Adafruit_SSD1306 library in .h fie
I have a project which includes OLED display, so I decided to use Adafruit_SSD1306 library. But I have problem with compiling code, which uses this library, in another .h file.
When I use this library in .ino file, everythings works, but in OLED.h file I get this error:
collect2.exe: error: ld returned 1 exit status
Multiple libraries found "DallasTemperature.h"
 Used: C:\Users\luky\Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master
Multiple libraries found "OneWire.h"
 Used: C:\Users\luky\Documents\Arduino\libraries\OneWire-master
Multiple libraries found "SPI.h"
 Used: C:\Users\luky\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\SPI
Multiple libraries found "Wire.h"
 Used: C:\Users\luky\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\Wire
Multiple libraries found "Adafruit_GFX.h"
 Used: C:\Users\luky\Documents\Arduino\libraries\Adafruit_GFX_Library
Multiple libraries found "Adafruit_SSD1306.h"
 Used: C:\Users\luky\Documents\Arduino\libraries\Adafruit_SSD1306
Multiple libraries found "SrcWrapper.h"
 Used: C:\Users\luky\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\SrcWrapper
Byly nalezené násobné knihovny "Adafruit_I2CDevice.h"
 Použitý: C:\Users\luky\Documents\Arduino\libraries\Adafruit_BusIO

The error is from this piece of code:
#include <SPI.h>
#include <Wire.h>

TwoWire Wire1(PB9, PB8); // Use STM32´s I2C2

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

STM32 Bluepill board is used.

Not sure if it solves the problem, but using #include after any code or variable declarations is not good coding practice. Put all #includes at the beginning.

Thanks thats good note.

But its still dont works

Sorry for that ... did you check if you installed multiple same-named libraries (maybe different versions?). Try to compile some sample sketches to see if something is wrong in your own code or within the libraries installation.

Sample sketches compile correctly, also when I use the library in my .ino file, everythings works correctly. Only problem is that my code is very long and it would be very jumble to include all the display code into this main (.ino) file. So I triing to write display code into another .h and .cpp file and then include it into the main file. But that´s the point where I get the compilation error.

Did you use #ifndef ___H checks for not including the same include file twice? (it should not matter for your errors, but something to check).

Yes, I used..
#ifndef __OLED__
#define __OLED__
#endif

You also could check if you can find multiple equally named libraries somewhere on your computer and remove them (after making a backup)

I also tried that. There is just the 1 library. Its very strange problem xD

Than I'm out of ideas ... maybe someone with experience with one of these libraries can answer.

That would be great. Thanks for help Michel Keijzers

Maybe https://www.youtube.com/watch?v=jkNkpzy8TbY helps?

It looks like for some reason it can't find Adafruit_I2CDevice.h which is part of Adafruit_BusIO, which is supposed to be automatically installed when you install Adafruit_SSD1306. Try to install it either via Library Manager on IDE or download it from Adafruit_BusIO. Personally I dislike anything from Adafruit, it is bloated and you ask for a money they gives you the entire jungle with all the dependencies loaded. There are much simpler SSD1602 library out there.


text:
Uploading arduino code to race drone flight controller
I am working on VTOL aircraft and currently I am looking for some good board as flight controller (FC). I could made it by myself, but it requests lot of time. I was thinking about one of fpv drone FC (I have avaiable this one:
https://www.banggood.com/cs/Original-Airbot-Omnibus-F4-Pro-V3-Flight-controller-SD-5V-3A-BEC-OSD-Current-Sensor-LC-Filter-p-1319177.html?gmcCountry=CZ&currency=CZK&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=lijing&utm_campaign=ssc-cz-cs-all-newcustom-ncv80-1118&gclid=CjwKCAjwqJ_1BRBZEiwAv73uwEgBJQ1B3dcKvZJZy2lR5-wN-XC150Ybn0kZObpUQbgkbvKiN_fY5BoCCVEQAvD_BwE&cur_warehouse=CN
This board has very small dimensions and it has already everything I need. The problem is that it is made for softwares like betaflight etc. It uses STM32 F405 so I tried to add STM 32 support for arduino (https://github.com/stm32duino/Arduino_Core_STM32) and upload arduino code in it.
I had to install stm32 cube programmer and because this board is not one of arduino boards I have to build the code for different board with same processor (FEATHER_F405). Because of it I have to change board pinout in this file (C:\Users\\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\variants\FEATHER_F405). I checked if are those pins correct (in code I command to those pins to be High and then Low while I was measuring them with multimeter). So all the pins are correct. I was able to blik the onboard LED and beep the buzzer. The only problem I have is serial communication. I tried to send some Strings to computer via serial port, but I didnt received any data. Here is sample code that I used:
#include <SoftwareSerial.h>

#define LED 4 //PB_5   //Inverted (High => LED ON)
#define BUZZ 3 //PB_4

#define _RX1 D0 //PA_10
#define _TX1 D1 //PA_9

//#define D_P 35 //PA_11
//#define D_M 36 //PA_12

//SoftwareSerial mySerial(_RX1, _TX1); // RX, TX
HardwareSerial  hwSerial_1(_RX1, _TX1);   // RX, TX

void setup() {

  hwSerial_1.begin(9600);
 //mySerial.begin(9600);

  pinMode(LED,OUTPUT);
  pinMode(BUZZ,OUTPUT);

  //pinMode(_RX1,OUTPUT);
  //pinMode(_TX1,OUTPUT);

  //pinMode(D_P,OUTPUT);
  //pinMode(D_M,OUTPUT);
}

void loop() {

  digitalWrite(LED, HIGH);
  /*
  digitalWrite(_RX1, HIGH);
  digitalWrite(_TX1, HIGH);
  digitalWrite(D_P, HIGH);
  digitalWrite(D_M, HIGH);*/

  delay(1000);

  digitalWrite(LED, LOW);
  /*
  digitalWrite(_RX1, LOW);
  digitalWrite(_TX1, LOW);
  digitalWrite(D_P, LOW);
  digitalWrite(D_M, LOW);*/

  delay(1000);

  digitalWrite(BUZZ, HIGH);
  delay(100);
  digitalWrite(BUZZ, LOW);
  delay(1000);

  hwSerial_1.println("HelloWorld");
  //mySerial.println("HelloWorld");

}

I tried to run serial communication via USB and via UART1 (I used USB/ TTL conventer -> FT232), but non of these works. I also tried to use software serial and hardware serial library, but it didnt helped.
Do you have any advices how to make serial communication work?

Sorry for answering this late to this problem but I stumbled on the very same issue. After many hours of debugging, here is what I've found:

The default serial (e.g. the serial that you will use through the object Serial) is actually what is labelled RX3 and TX3 on the board and is mapped like so:

RX3 -> PB_11
TX3 -> PB_10

Serial6 is connected through an inverter (5v becomes 0v and vice versa) and can be used as an SBUS line. Serial 6 is mapped like so:

RX6 -> PC_7
TX6 -> PC_6

Serial1 is mapped like so:

RX1 -> PA_10
TX1 -> PA_9
however, PA_10 and PA_11 are not used as UARTs on the FEATHER board. In order to enable them, you can edit the file hardware/stm32/2.3.0/variants/STM32F4xx/F405RGT_F415RGT/PeripheralPins_FEATHER_F405.c.

In the array PinMap_UART_TX (line 178), uncomment the line regarding the pin PA_9 and comment the line regarding the pin PB_6.
In the array PinMap_UART_RX (line 193), uncomment the line regarding the pin PA_10 and comment the line regarding the pin PB_7.

However, if you try to read from this uart you will probably receive garbage data because the Feather F405 board uses a 12MHz external oscillator, when the omnibus F4 uses a 8MHz clock. To fix this, you can go to the files that define the Feather F405 : hardware/stm32/2.3.0/variants/STM32F4xx/F405RGT_F415RGT/variant_FEATHER_F405.h line 178 you will read : #define HSE_VALUE 12000000U. This has to be changed into : #define HSE_VALUE 8000000U.


text:
Problem with STM32 and SDFat lib on other SPI port
I am using STM32F103C8 and I am triing to compile a code with SDFat library. The problem is I need to use the second channel of the SPI1 (pins PB5,PB4,PB3, PA15):

I found out that is possible to use SDFat lib and include SPIClass inside its constructor. Then I could use this code:
SPIClass SPI_1(PB5,PB4,PB3, PA15);
SdFat sd(&SPI_1);

The problem is this compliation error:
no matching function for call to 'SdFat::SdFat(SPIClass*)'

Do you have any idea how to solve this error or how to work with SD card on different pins?
Here is source code of this library:
https://github.com/greiman/SdFat/blob/master/src/SdFat.h

is IMPLEMENT_SPI_PORT_SELECTION or DOXYGEN defined anywhere?  What is it defined as?

That´s inside SDFat library. I am not sure what does it mean

Well if it is defined as 0 or isn’t defined then that constructor you underlined is not part of the code.  That preprocessor directive decides if that line will be included or not.  You’ll have to look and see if you can find it.

Can you share your schematic? I am trying to do the same but it is always failing to initialize.

Ok, I found out that the sdFat library is not supported on stm32 bluepill (sd card HAL peripherals are not enabled), so I decided to use basic Arduino SD library (it uses SPI commands, not HAL).
Also I have to change pins (from SPI1_1 to SPI1_2) in variant.h and PeripheralPins.c files of bluepill board. - And finally it works (SPI1_2).


text:
Subscribing to Bluefruit LE Friend with ArduinoBLE not working
I've been using an Arduino Nano 33 BLE to communicate with my PC over the BlueFruit LE Friend's UART characteristic. Using the default ArduinoBLE library, I'm able to connect to the BlueFruit from the Nano 33 as a central device, and write to the BlueFruit and have it show up in a serial terminal. I can get the Nano 33 to read from the Bluefruit as well, by sending a Characteristic.read() request and a subsequent Charcterisitc.readValue() command. Subscribing to the rx characterisitic on the Nano 33 does NOT work, however, even though the Bluefruit's info page says that the rx characterisitc (address 0x0003) is capable of Notify. I need to be able to subscribe, so that I can use the characteristic.valueUpdated() function to know when new data is available. Here is the relevant code:
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}

// discover peripheral attributes
Serial.println("Discovering attributes ...");
displayNum('A');
if (peripheral.discoverAttributes()) {
  Serial.println("Attributes discovered");
  displayNum(-1);
} else {
  Serial.println("Attribute discovery failed!");
  peripheral.disconnect();
  displayError('A');
  return;
}

// retrieve the TX characteristic
BLECharacteristic txCharacteristic = peripheral.characteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
BLECharacteristic rxCharacteristic = peripheral.characteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e");

// make sure BlueFruit UART characteristics have been loaded properly are of
// proper format
if (!txCharacteristic) {
  Serial.println("Peripheral does not have TX characteristic!");
  peripheral.disconnect();
  return;
} else if (!txCharacteristic.canWrite()) {
  Serial.println("Peripheral does not have a writable TX characteristic!");
  peripheral.disconnect();
  return;
}
if (!rxCharacteristic) {
  Serial.println("Peripheral does not have RX characteristic!");
  peripheral.disconnect();
  return;
} else if (!rxCharacteristic.canSubscribe()) {
  Serial.println("rxCharacteristic is not subscribable!");
  peripheral.disconnect();
  return;
} else if (!rxCharacteristic.subscribe()) {
  Serial.println("rxCharacteristic subscription failed!");
  peripheral.disconnect();
  return;
}

What's strange is that Characteristic.canSubscribe() method returns true, and it is only when I actually try to subscribe that my error message is triggered. This code is also basically taken directly from the ArduinoBLE SensorTag example, so I'm not sure if this is an issue with the Arduino library or the Bluefruit, so any input would be appreciated.

As an update, I'm able to get notifications through the BlueFruit Connect app, which makes me think that the issue has something more to do with the Arduino library.


text:
HTU21 on GY-21 breakout board I2C problem
I am interfacing the HTU21D sensor with my nodeMCU v3. All good! I managed to get some readings etc. But when I re-upload my code the device does not respond. If I remove the power supply from the pin and hard reset it, it works again. I have exactly the same problem using the Sparkfun library, so it seems more of a hardware problem. Anyone else had the same problem?
link to the sparkfun library
https://github.com/sparkfun/SparkFun_HTU21D_Breakout_Arduino_Library
for reference, here is my code
   This program interfaces the HTU21 temp/humidity sensor via I2C
*/

#include <Wire.h>
#include <Math.h>

const int HTU21_ADDR = 0x40;
const int Trigger_Temp_Measurement = 0xE3;// hold master
const int Trigger_Hum_Measurement = 0xE5; // hold master
const int Trigger_Temp = 0xF3; //No Hold Master
const int Trigger_Hum = 0xF5; //No Hold Master

int16_t Temp, Hum;//variables to store temp and humidity
int8_t TmpCrc, HumCrC;

void setup() {// put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(HTU21_ADDR);
  Wire.write(0xFE);
  Wire.endTransmission(true);

}

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

}

void TempReading() {

  Wire.beginTransmission(HTU21_ADDR);
  Wire.write(Trigger_Temp_Measurement);
  Wire.endTransmission();

  Wire.requestFrom(HTU21_ADDR, 3, true);
  if (Wire.available() <= 3) {
    Temp = (Wire.read() << 8) | (Wire.read() );
    TmpCrc = Wire.read();
  }
  float TempCalc = -46.85 + (175.72 * ((float)Temp / (pow(2, 16))));
  Serial.print("Temperature \t");
  Serial.print(TempCalc);
  //Serial.println(TmpCrc, HEX);

}

void HumReading() {
  Wire.beginTransmission(HTU21_ADDR);
  Wire.write(Trigger_Hum_Measurement);
  Wire.endTransmission();

  Wire.requestFrom(HTU21_ADDR, 3, true);
  if (Wire.available() <= 3) {
    Hum = (Wire.read() << 8) | (Wire.read());
    HumCrC = Wire.read();
  }

  float HumCalc = -6 + 125 * (Hum / (pow(2, 16)));
  Serial.print("\t Humidity \t");
  Serial.println(HumCalc);
  //Serial.println(HumCrC, HEX);

}```

Are you also resetting the slave device together with the nodeMCU? When you disrupt the I2C communication at the wrong time, the slave might be in a bad state, blocking the bus. Also you might not want to spam the I2C and Serial bus (because you don't have any delay or such in your loop())

Well If I press reset it would run through the setup loop which would reset the device. This would indeed NOT work if the I2C bus is in a bad state. What could be a solution to reset the bus?

Does the setup really run completely? How do you know that? With reset I mean a real hard reset, not a command reset. Only a hard reset would reset the I2C bus

Yes the setup runs completely. I found out that the bus hangs if I terminate communication by uploading new code to the board. I found a piece of code that releases the bus which works.

Yes the setup runs completely. I found out that the bus hangs if I terminate communication by uploading new code to the board. I found a piece of code that releases the bus which works. See below:
#if defined(TWCR) && defined(TWEN)
  TWCR &= ~(_BV(TWEN)); //Disable the Atmel 2-Wire interface so we can control the SDA and SCL pins directly
#endif

  pinMode(SDA, INPUT_PULLUP); // Make SDA (data) and SCL (clock) pins Inputs with pullup.
  pinMode(SCL, INPUT_PULLUP);

  boolean SCL_LOW = (digitalRead(SCL) == LOW); // Check is SCL is Low.
  if (SCL_LOW) { //If it is held low Arduno cannot become the I2C master.
    return 1; //I2C bus error. Could not clear SCL clock line held low
  }

  boolean SDA_LOW = (digitalRead(SDA) == LOW);  // vi. Check SDA input.
  int clockCount = 20; // > 2x9 clock

  while (SDA_LOW && (clockCount > 0)) { //  vii. If SDA is Low,
    clockCount--;
    // Note: I2C bus is open collector so do NOT drive SCL or SDA high.
    pinMode(SCL, INPUT); // release SCL pullup so that when made output it will be LOW
    pinMode(SCL, OUTPUT); // then clock SCL Low
    delayMicroseconds(10); //  for >5uS
    pinMode(SCL, INPUT); // release SCL LOW
    pinMode(SCL, INPUT_PULLUP); // turn on pullup resistors again
    // do not force high as slave may be holding it low for clock stretching.
    delayMicroseconds(10); //  for >5uS
    // The >5uS is so that even the slowest I2C devices are handled.
    SCL_LOW = (digitalRead(SCL) == LOW); // Check if SCL is Low.
    int counter = 20;
    while (SCL_LOW && (counter > 0)) {  //  loop waiting for SCL to become High only wait 2sec.
      counter--;
      delay(100);
      SCL_LOW = (digitalRead(SCL) == LOW);
    }
    if (SCL_LOW) { // still low after 2 sec error
      return 2; // I2C bus error. Could not clear. SCL clock line held low by slave clock stretch for >2sec
    }
    SDA_LOW = (digitalRead(SDA) == LOW); //   and check SDA input again and loop
  }
  if (SDA_LOW) { // still low
    return 3; // I2C bus error. Could not clear. SDA data line held low
  }

  // else pull SDA line low for Start or Repeated Start
  pinMode(SDA, INPUT); // remove pullup.
  pinMode(SDA, OUTPUT);  // and then make it LOW i.e. send an I2C Start or Repeated start control.
  // When there is only one I2C master a Start or Repeat Start has the same function as a Stop and clears the bus.
  /// A Repeat Start is a Start occurring after a Start with no intervening Stop.
  delayMicroseconds(10); // wait >5uS
  pinMode(SDA, INPUT); // remove output low
  pinMode(SDA, INPUT_PULLUP); // and make SDA high i.e. send I2C STOP control.
  delayMicroseconds(10); // x. wait >5uS
  pinMode(SDA, INPUT); // and reset pins as tri-state inputs which is the default state on reset
  pinMode(SCL, INPUT);
  return 0; // all ok
}

Thanks for pointing me in the right direction!