Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Append to an existing file stored in SD Card connected to Arduino
In this tutorial, we will, as the title suggests, see how to append to a file in and SD Card connected to Arduino. Actually, it is quite simple. If you have gone through any previous articles on SD Card, then you only need to know thatmyFile = SD.open("example.txt", FILE_WRITE);opens example.txt in the append mode only. Thereafter, myFile.println(dataString);appends to the existing file, and doesn’t overwrite the existing content.If you haven’t gone through any other articles on SD Card, I’d suggest reading the "Store a new file in SD Card connected to Arduino" article. That is a detailed article containing the circuit ...
Read MoreConnect SD Card with Arduino and get Card Info
In this tutorial, we will connect our Arduino Uno to an SD Card and extract the card info.Circuit DiagramThe circuit diagram is shown below −As you can see, you need to make the following connections −SD Card HolderArduino UnoVcc5VGNDGNDMISO12MOSI11SCK13CS10Only for the Vcc, make sure that your SD Card Holder takes 5V as input. If it takes in 3.3V, connect it to the 3.3V pin on Arduino Uno.Code WalkthroughWe will be walking through the example code that comes in with the inbuilt SD library. You can access it from File → Examples → SD → CardInfoWe begin with the inclusion of ...
Read MoreWait for user input to start a sketch in Arduino
A problem faced by several people using Arduino, or any microcontroller board for that matter, is that you may forget to start the Serial Monitor before programming the board, and miss some print statements by the time you open the Serial Monitor.One way to overcome this is to start the sketch only after an input is received from the user, via the Serial Monitor. This will ensure that you don’t miss any prints on the Serial Monitor because of the delay in starting the Serial Monitor.Examplevoid setup() { // put your setup code here, to run once: Serial.begin(9600); ...
Read MoreReserve memory in Arduino for string manipulation
It may happen that a string may change length dynamically during the execution of a program.If you want to ensure that there is always enough memory available for your string, you can reserve some memory using the reserve() function.SyntaxString1.reserve(n_bytes);Where String1 is the string for which you are reserving memory, and n_bytes (unsigned int) is the number of bytes to be reserved in the memory.ExampleString s1 = "Hello"; void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); s1.reserve(20); s1 = s1+" World!"; Serial.println(s1); s1 = s1+" I'm now trying ...
Read MoreCompare Strings in Arduino
Arduino has an inbuilt compareTo() function that helps compare which string comes before another. Very crudely, you can think of it as this: if you are given two strings, which one will come first in a dictionary.SyntaxString1.compareTo(String2)Where String1 and String2 are the two strings to be compared. This function returns an integer. Here’s the interpretation of the value of the integer −Negative − String1 comes before String20 − String1 and String2 are equalPositive − String2 comes before String1Please note that this function is case sensitive. So ‘A’ comes before ‘a’ and ‘B’ comes before ‘a’. But ‘a’ comes before ‘b’. Also, ...
Read MoreRead values sent by Serial Monitor to Arduino
The Serial Monitor of Arduino has a text box at the top, through which, users can send in text to the Arduino board.The text can be read by Serial.read(). Also, the Serial.available() function can be used to check if there is any data to read. It returns the number of characters or bytes available for reading, i.e., the number of bytes stored in the serial receive buffer.ExampleUsing these functions, let’s create a simple echo program for Arduino. The code for the same can be found below −void setup() { // put your setup code here, to run once: ...
Read MoreHow to Remove Characters from a String in Arduino?
The remove function in Arduino helps you remove one or more characters from within a string.SyntaxmyString.remove(index, count)Here, index refers to the index from where removal has to start. Note that indexing in Arduino starts with 0. Thus, within string "Hello", 'H' is at index 0, 'e' is at index 1, and so on.The count argument is optional, and it specifies the number of characters to remove. If you don’t specify the count, then all characters starting from index till the end of the string will be removed. If you specify count as say, 3, then 3 characters starting from index position will ...
Read MoreSet characters at a specific position within the string in Arduino
In case you don’t want to overwrite a string, but just change a character at a specific position, Arduino provides the setCharAt() function exactly for that.SyntaxString1.setCharAt(ind, new_char);String 1 is the string to modify. ind is the index where the character needs to be set. new_char is the value of the new character that needs to be set.This function returns nothing, and modifies the string in place.ExampleThe following example illustrates the use of this function.void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); String string1 = "Hello World!"; Serial.println(string1); string1.setCharAt(4, ...
Read MoreGet ASCII table in Arduino
In this article, we will walkthrough the example code in Arduino, which helps generate the ASCII table in the Serial Monitor output. For your reference, this is what the ASCII table looks like − http://www.asciitable.com/It contains the character, followed by its ASCII code in decimal, hexadecimal, and sometimes, even octal and binary representations. In this example, we will print out all these representations for printable ASCII characters. Remember that the first printable ASCII character starts from number 33, and the printable characters go on up to number 126. Since we will print out the ASCII table on the Serial Monitor, ...
Read MoreGet the last occurrence of a substring within a string in Arduino
Just like indexOf() helps identify the first occurrence of a substring within a string, the lastIndexOf() function helps identify the last occurrence. This is because lastIndexOf() performs backward search, while indexOf() performs forward search.syntaxmyString.lastIndexOf(substr)Where substr is the substring to search for in myString. It can be a character or a string.Just like indexOf(), this function also accepts an optional from argument, in case you want the backward search to begin from a specific index. The syntax in that case is −SyntaxmyString.lastIndexOf(substr, from)Just like indexOf(), this function either returns the last index of the substring within the string, or it returns -1 if no match ...
Read More