<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=Arduino_sketch_on_pcduino</id>
	<title>Arduino sketch on pcduino - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=Arduino_sketch_on_pcduino"/>
	<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=Arduino_sketch_on_pcduino&amp;action=history"/>
	<updated>2026-07-21T20:03:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.2</generator>
	<entry>
		<id>https://w.electrodragon.com/w/index.php?title=Arduino_sketch_on_pcduino&amp;diff=4808&amp;oldid=prev</id>
		<title>Chao: /* View .c Source Sketch at sample */</title>
		<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=Arduino_sketch_on_pcduino&amp;diff=4808&amp;oldid=prev"/>
		<updated>2013-07-21T14:44:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;View .c Source Sketch at sample&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Setup (one time)==&lt;br /&gt;
=== Install the Git (not necessary for new version of ubuntu)===&lt;br /&gt;
If not already done, set up git. Do this using the command:&lt;br /&gt;
 ubuntu@ubuntu:~$ sudo apt-get install git&lt;br /&gt;
Make sure you’re in your home folder by typing&lt;br /&gt;
 ubuntu@ubuntu:~$ cd&lt;br /&gt;
 ubuntu@ubuntu:~$ pwd&lt;br /&gt;
and see&amp;lt;br /&amp;gt;&lt;br /&gt;
 /home/Ubuntu&lt;br /&gt;
=== Now download the distribution ===&lt;br /&gt;
Typing&amp;lt;br /&amp;gt;&lt;br /&gt;
 ubuntu@ubuntu:~$ git clone https://github.com/pcduino/c_enviroment&lt;br /&gt;
And will see &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Cloning into 'c_enviroment'...&lt;br /&gt;
 remote: Counting objects: 250, done.&lt;br /&gt;
 remote: Compressing objects: 100% (166/166), done.&lt;br /&gt;
 remote: Total 250 (delta 87), reused 232 (delta 69)&lt;br /&gt;
 Receiving objects: 100% (250/250), 302.59 KiB | 78 KiB/s, done.&lt;br /&gt;
 'Resolving deltas: 100% (87/87), done.&lt;br /&gt;
You should now have a folder called c_enviroment. You can check by typing ls&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ubuntu@ubuntu:~$ ls&lt;br /&gt;
&lt;br /&gt;
And you will see&amp;lt;br /&amp;gt;&lt;br /&gt;
 Desktop Documents Downloads Music Pictures Public Templates Videos arduino c_enviroment sample&lt;br /&gt;
&lt;br /&gt;
==Initial look around==&lt;br /&gt;
Change into the c_envoroment folder&amp;lt;br /&amp;gt;&lt;br /&gt;
 ubuntu@ubuntu:~$ cd c_enviroment&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment$ ls&lt;br /&gt;
&lt;br /&gt;
=== Make to complie ===&lt;br /&gt;
Now run make to make the libraries and the examples with the following command&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment$ make&lt;br /&gt;
You should see a series of compile commands occurring without errors with the last line being:&lt;br /&gt;
 make[1]: Leaving directory `/home/ubuntu/c_enviroment/sample'&lt;br /&gt;
&lt;br /&gt;
=== View executable files after make at c_environment/output/test ===&lt;br /&gt;
They are basically two folders, sample and subfolder test&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The resulting binary files are found in the output/test folder&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment$ cd output/test&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/output/test$ ll&lt;br /&gt;
and will see &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ls_test_folder.png|400px]]&amp;lt;br /&amp;gt;&lt;br /&gt;
=== View source .c sketch files list at c_environment/sample ===&lt;br /&gt;
The source for each one is in sample folder&amp;lt;br /&amp;gt;&lt;br /&gt;
[[File:Ls_sample_folder.png|400px]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== View .c Source Sketch ===&lt;br /&gt;
To view the contents of a sample sketch, (this example we’ll look at the contents of linker_led_test.c) type:&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ cat linker_led_test.c&lt;br /&gt;
&lt;br /&gt;
And will see:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Arduino&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
* LED test program&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;core.h&amp;gt;&lt;br /&gt;
int led_pin = 1;&lt;br /&gt;
&lt;br /&gt;
void setup()&lt;br /&gt;
{&lt;br /&gt;
if(argc != 2){&lt;br /&gt;
goto _help;&lt;br /&gt;
}&lt;br /&gt;
led_pin = atoi(argv[1]);&lt;br /&gt;
if((led_pin &amp;lt; 0) || (led_pin &amp;gt; 13)){&lt;br /&gt;
goto _help;&lt;br /&gt;
}&lt;br /&gt;
pinMode(led_pin, OUTPUT);&lt;br /&gt;
return;&lt;br /&gt;
&lt;br /&gt;
_help:&lt;br /&gt;
printf(&amp;quot;Usage %s LED_PIN_NUM(0-13)n&amp;quot;, argv[0]);&lt;br /&gt;
exit(-1);&lt;br /&gt;
}&lt;br /&gt;
void loop()&lt;br /&gt;
{&lt;br /&gt;
digitalWrite(led_pin, HIGH); // set the LED on&lt;br /&gt;
delay(1000); // wait for a second&lt;br /&gt;
digitalWrite(led_pin, LOW); // set the LED off&lt;br /&gt;
delay(1000); // wait for a second&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing an existing sketch ==&lt;br /&gt;
You will probably want to change some of these samples as an initial play so will need a text editor. We tend to use [[nano Editor]], but you may already have a favourite. &lt;br /&gt;
Let’s use the same sketch as the example, type:&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ nano linker_led_test.c&lt;br /&gt;
You should see something like:&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Nano_arduino_sketch.jpg|400px]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating your own sketch ==&lt;br /&gt;
Now lets create our own sketch and work out how to compile it so it runs. It will be a button on pin 7 that when pressed, turns on an LED on pin 8.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While in the sample folder, type:&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ nano button_led.c&lt;br /&gt;
An empty nano screen should appear.&amp;lt;br /&amp;gt;&lt;br /&gt;
Copy and paste the following code into it. (Remember to paste in nano at the cursor, just right click the mouse button).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Arduino&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;core.h&amp;gt; // Required first line to run on pcDuino&lt;br /&gt;
int ledPin = 8;&lt;br /&gt;
int buttonPin = 7;&lt;br /&gt;
// variables will change:&lt;br /&gt;
int buttonState = 0; // variable for reading the pushbutton status&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
// initialize the LED pin as an output:&lt;br /&gt;
pinMode(ledPin, OUTPUT);&lt;br /&gt;
// initialize the pushbutton pin as an input:&lt;br /&gt;
pinMode(buttonPin, INPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop(){&lt;br /&gt;
// read the state of the pushbutton value:&lt;br /&gt;
buttonState = digitalRead(buttonPin);&lt;br /&gt;
&lt;br /&gt;
// check if the pushbutton is pressed.&lt;br /&gt;
// if it is, the buttonState is HIGH:&lt;br /&gt;
if (buttonState == HIGH) {&lt;br /&gt;
// turn LED on:&lt;br /&gt;
digitalWrite(ledPin, HIGH);&lt;br /&gt;
}&lt;br /&gt;
else {&lt;br /&gt;
// turn LED off:&lt;br /&gt;
digitalWrite(ledPin, LOW);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Above sketch modified from http://arduino.cc/en/tutorial/button&lt;br /&gt;
&lt;br /&gt;
== Modify the Makefile and compile ==&lt;br /&gt;
Now we need to add this new sketch to the Makefile in the samples folder. Open the Makefile with nano (or your favourite text editor)&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ nano Makefile&lt;br /&gt;
&lt;br /&gt;
You will see a section that lists all the OBJS something like:&lt;br /&gt;
 OBJS = io_test adc_test pwm_test spi_test adxl345_test serial_test liquidcrystal_i2c liquidcrystal_spi interrupt_test tone_test&lt;br /&gt;
 OBJS += linker_led_test linker_potentiometer_test linker_tilt_test linker_light_sensor_test linker_button_test&lt;br /&gt;
 OBJS += linker_touch_sensor_test linker_magnetic_sensor_test linker_temperature_sensor_test linker_joystick_test&lt;br /&gt;
 OBJS += linker_rtc_test linker_sound_sensor_test linker_buzzer_test linker_hall_sensor_test linker_led_bar_test linker_relay_test&lt;br /&gt;
 OBJS += pn532_readAllMemoryBlocks pn532readMifareMemory pn532readMifareTargetID pn532writeMifareMemory&lt;br /&gt;
&lt;br /&gt;
We’re going to add a line to the end of this with the name of the scketch we just created:&lt;br /&gt;
 OBJS += button_led&lt;br /&gt;
Note, we don’t put the .c on the end.&amp;lt;br /&amp;gt;&lt;br /&gt;
Save the file and exit nano using &amp;lt;CTRL&amp;gt;X with a y and &amp;lt;enter&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
We now run make by typing&amp;lt;br /&amp;gt;&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ make&lt;br /&gt;
You should see a whole bunch of text with the end being:&lt;br /&gt;
 button_led.c -o ../output/test/button_led ../libarduino.a&lt;br /&gt;
If all went well, you can go to the output/test folder and find your executable you have created:&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/sample$ cd ../output/test/&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/output/test$ ll&lt;br /&gt;
and will see:&lt;br /&gt;
 total 676&lt;br /&gt;
 drwxrwxr-x 2 ubuntu ubuntu 4096 Apr 27 07:51 ./&lt;br /&gt;
 drwxrwxr-x 3 ubuntu ubuntu 4096 Apr 27 06:49 ../&lt;br /&gt;
 -rwxrwxr-x 1 ubuntu ubuntu 13868 Apr 27 07:51 adc_test*&lt;br /&gt;
 -rwxrwxr-x 1 ubuntu ubuntu 28284 Apr 27 07:51 adxl345_test*&lt;br /&gt;
 -rwxrwxr-x 1 ubuntu ubuntu 13668 Apr 27 07:51 button_led*&lt;br /&gt;
 …..(not showing rest of listing here)&lt;br /&gt;
== Run your sketch ==&lt;br /&gt;
To run it, once you have wired up a switch and led to the right pins, type:&lt;br /&gt;
 ubuntu@ubuntu:~/c_enviroment/output/test$ ./button_led&lt;br /&gt;
To stop the program, &amp;lt;Ctrl&amp;gt;C&lt;br /&gt;
== A quick re-cap ==&lt;br /&gt;
Add #include &amp;lt;core.h&amp;gt; to the top of your sketch.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create your sketch in the samples folder (if your familiar with linux, makefiles, and compiling code, you could set up your own)&amp;lt;br /&amp;gt;&lt;br /&gt;
Add the filename to the Makefile in the samples folder in the OBJS section without the .c&amp;lt;br /&amp;gt;&lt;br /&gt;
Run make&amp;lt;br /&amp;gt;&lt;br /&gt;
Run the executable from the output/test folder.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can introduce command line arguments into your sketch to make it more transportable.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[category:PCduino]]&lt;/div&gt;</summary>
		<author><name>Chao</name></author>
	</entry>
</feed>