mirror of
https://github.com/platformio/platformio-core.git
synced 2025-10-04 17:40:57 +02:00
Reorganise examples
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
Arduino Example: Build \*.ino file with external Adafruit library
|
||||
=================================================================
|
||||
|
||||
1. Download ``platformio``
|
||||
`sources <https://github.com/ivankravets/platformio/archive/develop.zip>`_
|
||||
2. Extract ZIP archive
|
||||
3. Then run these commands:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Change directory to example
|
||||
$ cd platformio-develop/examples/arduino-adafruit-library/
|
||||
|
||||
# Install Atmel AVR development platform with Arduino Framework
|
||||
$ platformio install atmelavr
|
||||
|
||||
# Process example project
|
||||
$ platformio run
|
||||
|
||||
# Upload firmware
|
||||
$ platformio run -t upload
|
||||
|
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Project Configuration File
|
||||
#
|
||||
# A detailed documentation with the EXAMPLES is located here:
|
||||
# http://docs.platformio.org/en/latest/projectconf.html
|
||||
#
|
||||
|
||||
# A sign `#` at the beginning of the line indicates a comment
|
||||
# Comment lines are ignored.
|
||||
|
||||
# Simple and base environment
|
||||
# [env:mybaseenv]
|
||||
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
||||
# framework =
|
||||
# board =
|
||||
#
|
||||
# Automatic targets - enable auto-uploading
|
||||
# targets = upload
|
||||
|
||||
[env:microduino]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = 644pa16m
|
||||
|
||||
# targets = upload
|
185
examples/atmelavr-and-arduino/arduino-adafruit-library/src/EchoServer.ino
Executable file
185
examples/atmelavr-and-arduino/arduino-adafruit-library/src/EchoServer.ino
Executable file
@@ -0,0 +1,185 @@
|
||||
|
||||
/***************************************************
|
||||
Adafruit CC3000 Breakout/Shield TCP Echo Server
|
||||
|
||||
This is a simple implementation of the echo
|
||||
protocol, RFC 862 http://tools.ietf.org/html/rfc862 ,
|
||||
for the Arduino platform and Adafruit CC3000 breakout
|
||||
or shield. This sketch will create a TCP server that
|
||||
listens by default on port 7 and echos back any data
|
||||
received. Up to 3 clients can be connected concurrently
|
||||
to the server. This sketch is meant as an example of how
|
||||
to write a simple server with the Arduino and CC3000.
|
||||
|
||||
See the CC3000 tutorial on Adafruit's learning system
|
||||
for more information on setting up and using the
|
||||
CC3000:
|
||||
http://learn.adafruit.com/adafruit-cc3000-wifi
|
||||
|
||||
Requirements:
|
||||
|
||||
This sketch requires the Adafruit CC3000 library. You can
|
||||
download the library from:
|
||||
https://github.com/adafruit/Adafruit_CC3000_Library
|
||||
|
||||
For information on installing libraries in the Arduino IDE
|
||||
see this page:
|
||||
http://arduino.cc/en/Guide/Libraries
|
||||
|
||||
Usage:
|
||||
|
||||
Update the SSID and, if necessary, the CC3000 hardware pin
|
||||
information below, then run the sketch and check the
|
||||
output of the serial port. After connecting to the
|
||||
wireless network successfully the sketch will output
|
||||
the IP address of the server and start listening for
|
||||
connections. Once listening for connections, connect
|
||||
to the server from your computer using a telnet client
|
||||
on port 7.
|
||||
|
||||
For example on Linux or Mac OSX, if your CC3000 has an
|
||||
IP address 192.168.1.100 you would execute in a command
|
||||
window:
|
||||
|
||||
telnet 192.168.1.100 7
|
||||
|
||||
After connecting, notice that as you type input and
|
||||
press enter to send it the CC3000 will echo back exactly
|
||||
what you typed. Press ctrl-] and type quit at the prompt
|
||||
to close the telnet session.
|
||||
|
||||
On Windows you'll need to download a telnet client. PuTTY
|
||||
is a good, free GUI client:
|
||||
http://www.chiark.greenend.org.uk/~sgtatham/putty/
|
||||
|
||||
License:
|
||||
|
||||
This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com)
|
||||
and is released under an open source MIT license. See details at:
|
||||
http://opensource.org/licenses/MIT
|
||||
|
||||
This code was adapted from Adafruit CC3000 library example
|
||||
code which has the following license:
|
||||
|
||||
Designed specifically to work with the Adafruit WiFi products:
|
||||
----> https://www.adafruit.com/products/1469
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
#include <Adafruit_CC3000.h>
|
||||
#include <SPI.h>
|
||||
#include "utility/debug.h"
|
||||
#include "utility/socket.h"
|
||||
|
||||
// These are the interrupt and control pins
|
||||
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
|
||||
// These can be any two pins
|
||||
#define ADAFRUIT_CC3000_VBAT 5
|
||||
#define ADAFRUIT_CC3000_CS 10
|
||||
// Use hardware SPI for the remaining pins
|
||||
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
|
||||
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
|
||||
SPI_CLOCK_DIVIDER); // you can change this clock speed
|
||||
|
||||
#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters!
|
||||
#define WLAN_PASS "myPassword"
|
||||
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
|
||||
#define WLAN_SECURITY WLAN_SEC_WPA2
|
||||
|
||||
#define LISTEN_PORT 7 // What TCP port to listen on for connections. The echo protocol uses port 7.
|
||||
|
||||
Adafruit_CC3000_Server echoServer(LISTEN_PORT);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("Hello, CC3000!\n"));
|
||||
|
||||
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
|
||||
|
||||
/* Initialise the module */
|
||||
Serial.println(F("\nInitializing..."));
|
||||
if (!cc3000.begin())
|
||||
{
|
||||
Serial.println(F("Couldn't begin()! Check your wiring?"));
|
||||
while(1);
|
||||
}
|
||||
|
||||
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
|
||||
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
|
||||
Serial.println(F("Failed!"));
|
||||
while(1);
|
||||
}
|
||||
|
||||
Serial.println(F("Connected!"));
|
||||
|
||||
Serial.println(F("Request DHCP"));
|
||||
while (!cc3000.checkDHCP())
|
||||
{
|
||||
delay(100); // ToDo: Insert a DHCP timeout!
|
||||
}
|
||||
|
||||
/* Display the IP address DNS, Gateway, etc. */
|
||||
while (! displayConnectionDetails()) {
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* You can safely remove this to save some flash memory! */
|
||||
/*********************************************************/
|
||||
Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches"));
|
||||
Serial.println(F("since the .disconnect() function is never called, so the"));
|
||||
Serial.println(F("AP may refuse connection requests from the CC3000 until a"));
|
||||
Serial.println(F("timeout period passes. This is normal behaviour since"));
|
||||
Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n"));
|
||||
|
||||
// Start listening for connections
|
||||
echoServer.begin();
|
||||
|
||||
Serial.println(F("Listening for connections..."));
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Try to get a client which is connected.
|
||||
Adafruit_CC3000_ClientRef client = echoServer.available();
|
||||
if (client) {
|
||||
// Check if there is data available to read.
|
||||
if (client.available() > 0) {
|
||||
// Read a byte and write it to all clients.
|
||||
uint8_t ch = client.read();
|
||||
client.write(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Tries to read the IP address and other connection details
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool displayConnectionDetails(void)
|
||||
{
|
||||
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
|
||||
|
||||
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
|
||||
{
|
||||
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
|
||||
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
|
||||
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
|
||||
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
|
||||
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
|
||||
Serial.println();
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
Arduino Example: Build code with internal library
|
||||
=================================================
|
||||
|
||||
1. Download ``platformio``
|
||||
`sources <https://github.com/ivankravets/platformio/archive/develop.zip>`_
|
||||
2. Extract ZIP archive
|
||||
3. Then run these commands:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Change directory to example
|
||||
$ cd platformio-develop/examples/arduino-internal-library/
|
||||
|
||||
# Install Atmel AVR development platform with Arduino Framework
|
||||
$ platformio install atmelavr
|
||||
|
||||
# Process example project
|
||||
$ platformio run
|
||||
|
||||
.. image:: console-result.png
|
Binary file not shown.
After Width: | Height: | Size: 806 KiB |
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Project Configuration File
|
||||
#
|
||||
# A detailed documentation with the EXAMPLES is located here:
|
||||
# http://docs.platformio.org/en/latest/projectconf.html
|
||||
#
|
||||
|
||||
# A sign `#` at the beginning of the line indicates a comment
|
||||
# Comment lines are ignored.
|
||||
|
||||
# Simple and base environment
|
||||
# [env:mybaseenv]
|
||||
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
||||
# framework =
|
||||
# board =
|
||||
#
|
||||
# Automatic targets - enable auto-uploading
|
||||
# targets = upload
|
||||
|
||||
[env:arduino_pro5v]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = pro16MHzatmega168
|
||||
|
||||
# targets = upload
|
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
* See LICENSE for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* EEPROM Read
|
||||
*
|
||||
* Reads the value of each byte of the EEPROM and prints it
|
||||
* to the computer.
|
||||
* This example code is in the public domain.
|
||||
*
|
||||
* https://github.com/arduino/Arduino/blob/master/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
// start reading from the first byte (address 0) of the EEPROM
|
||||
int address = 0;
|
||||
byte value;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// read a byte from the current address of the EEPROM
|
||||
value = EEPROM.read(address);
|
||||
|
||||
Serial.print(address);
|
||||
Serial.print("\t");
|
||||
Serial.print(value, DEC);
|
||||
Serial.println();
|
||||
|
||||
// advance to the next address of the EEPROM
|
||||
address = address + 1;
|
||||
|
||||
// there are only 512 bytes of EEPROM, from 0 to 511, so if we're
|
||||
// on address 512, wrap around to address 0
|
||||
if (address == 512)
|
||||
address = 0;
|
||||
|
||||
delay(500);
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
Atmel AVR: Native Blink Example
|
||||
===============================
|
||||
|
||||
1. Download ``platformio``
|
||||
`sources <https://github.com/ivankravets/platformio/archive/develop.zip>`_
|
||||
2. Extract ZIP archive
|
||||
3. Then run these commands:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Change directory to example
|
||||
$ cd platformio-develop/examples/atmelavr-native-blink/
|
||||
|
||||
# Install Atmel AVR development platform
|
||||
$ platformio install atmelavr
|
||||
|
||||
# Process example project
|
||||
$ platformio run
|
||||
|
||||
.. image:: console-result.png
|
Binary file not shown.
After Width: | Height: | Size: 126 KiB |
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Project Configuration File
|
||||
#
|
||||
# A detailed documentation with the EXAMPLES is located here:
|
||||
# http://docs.platformio.org/en/latest/projectconf.html
|
||||
#
|
||||
|
||||
# A sign `#` at the beginning of the line indicates a comment
|
||||
# Comment lines are ignored.
|
||||
|
||||
# Simple and base environment
|
||||
# [env:mybaseenv]
|
||||
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
||||
# framework =
|
||||
# board =
|
||||
#
|
||||
# Automatic targets - enable auto-uploading
|
||||
# targets = upload
|
||||
|
||||
[env:arduino_pro5v]
|
||||
platform = atmelavr
|
||||
board_mcu = atmega168
|
||||
board_f_cpu = 16000000L
|
||||
|
||||
upload_protocol = arduino
|
||||
upload_speed = 19200
|
||||
|
||||
# targets = upload
|
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
* See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// make the LED pin an output for PORTB5
|
||||
DDRB = 1 << 5;
|
||||
|
||||
while (1)
|
||||
{
|
||||
_delay_ms(500);
|
||||
|
||||
// toggle the LED
|
||||
PORTB ^= 1 << 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user