5


Overview

I was recently playing with the Arduino Yun for a whole set of new projects, and I discovered that Arduino was providing an official REST API for the Arduino Yun, in the form of an Arduino sketch. And after using it for a while, I thought about a new idea: what not do the same for the Arduino platform in general?
But first, let see what a REST API really is. It’s actually a concept that is widely used by many web applications like SaaS (Software as a Service). REST stands for REpresentational State Transfer, and is a communication architecture that was created back in 2000. It defines many constraints that the architecture has to follow, the most important features being:
  • A client/server communication: a client sends a request to a server, and the server answers accordingly
  • A stateless communication: every request has to contain all the information so the server can understand it, without having to rely on some information stored on the server
  • A uniform interface to easily identify resources on the server
This allowed to standardise communication between web applications, and made them more scalable, faster, and simplified the development of more complex applications. And for our Arduino projects, it allows to standardise the communication between your Arduino and the external world via WiFi or Ethernet, and develop complex applications without having to modify your Arduino sketch every time.
Indeed, I have been using the CC3000 WiFi chip for a while, and the problem that I encountered while developing web applications using the CC3000 chip is that I had to create a new Arduino sketch for every application, that needs to be coordinated with the rest of the application, for example an interface running on my computer. For example, using this REST API, switching the state from a pin on the Arduino board can be done directly in the browser by typing the following URL:
With this REST API, it’s easy to load a sketch once for all on your Arduino, and then only work on the interface on your computer that makes REST calls on your Arduino board. And for now, this kind of interface was only available on the official Arduino boards, like the WiFi & Ethernet shields, and the Yun.
But I wanted to have the same on my CC3000 WiFi chip: make a sketch that will create a web server on the Arduino board, and then accept REST commands from an external client, like from an interface running on my computer. That's why I created a dedicated library that encapsulate these ideas, and even allows you to create your own functions that can be called from the API. And in this guide, we are going to see how to use this library.Hardware configuration
On the hardware side, you have a lot of options for this project. I tested it with an Arduino Uno board and an Adafruit CC3000 breakout board, but it should work with other Arduino boards like the Arduino Mega. You can also use the Adafruit CC3000 Shield to replace the breakout board.

I also added two LEDs to the project, just to visualise the effect of REST calls. But you can also add analog or digital sensors to the project to test other functions of the library.

To connect the breakout board, connect the IRQ pin of the CC3000 board to pin number 3 of the Arduino board, VBAT to pin 5, and CS to pin 10. Then, you need to connect the SPI pins to the Arduino board: MOSI, MISO, and CLK go to pins 11,12, and 13, respectively. Finally, take care of the power supply: Vin goes to the Arduino 5V, and GND to GND.

For the LEDs, I simply connected each of them in series with a 220 Ohm resistor, on pin number 7 and 8 of the Arduino board. The following picture summarises all the hardware connections:
components_schematic_bb.jpg

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

Flowchart

12เครื่องวัดความเร็วอะนาล็อกใช้ Arduino และเซ็นเซอร์ IR

10อัลตราโซนิกเซนเซอร์ตรวจจับระยะไกลใน ARDUINO พร้อม TINKERCAD